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