Blame tests/comparisons.c

Packit 80c72f
/* comparisons.c -- Comparison functions.
Packit 80c72f
Packit 80c72f
Copyright (C) 2008, 2009, 2011 INRIA
Packit 80c72f
Packit 80c72f
This file is part of GNU MPC.
Packit 80c72f
Packit 80c72f
GNU MPC is free software; you can redistribute it and/or modify it under
Packit 80c72f
the terms of the GNU Lesser General Public License as published by the
Packit 80c72f
Free Software Foundation; either version 3 of the License, or (at your
Packit 80c72f
option) any later version.
Packit 80c72f
Packit 80c72f
GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY
Packit 80c72f
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
Packit 80c72f
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
Packit 80c72f
more details.
Packit 80c72f
Packit 80c72f
You should have received a copy of the GNU Lesser General Public License
Packit 80c72f
along with this program. If not, see http://www.gnu.org/licenses/ .
Packit 80c72f
*/
Packit 80c72f
Packit 80c72f
#include "mpc-tests.h"
Packit 80c72f
Packit 80c72f
/* comparisons, see description in mpc-tests.h */
Packit 80c72f
int
Packit 80c72f
same_mpfr_value (mpfr_ptr got, mpfr_ptr ref, int known_sign)
Packit 80c72f
{
Packit 80c72f
   /* The sign of zeroes and infinities is checked only when
Packit 80c72f
      known_sign is true.                                    */
Packit 80c72f
   if (mpfr_nan_p (got))
Packit 80c72f
      return mpfr_nan_p (ref);
Packit 80c72f
   if (mpfr_inf_p (got))
Packit 80c72f
      return mpfr_inf_p (ref) &&
Packit 80c72f
            (!known_sign || mpfr_signbit (got) == mpfr_signbit (ref));
Packit 80c72f
   if (mpfr_zero_p (got))
Packit 80c72f
      return mpfr_zero_p (ref) &&
Packit 80c72f
            (!known_sign || mpfr_signbit (got) == mpfr_signbit (ref));
Packit 80c72f
   return mpfr_cmp (got, ref) == 0;
Packit 80c72f
}
Packit 80c72f
Packit 80c72f
int
Packit 80c72f
same_mpc_value (mpc_ptr got, mpc_ptr ref, known_signs_t known_signs)
Packit 80c72f
{
Packit 80c72f
   return    same_mpfr_value (mpc_realref (got), mpc_realref (ref), known_signs.re)
Packit 80c72f
          && same_mpfr_value (mpc_imagref (got), mpc_imagref (ref), known_signs.im);
Packit 80c72f
}