xref: /netbsd-src/external/lgpl3/mpc/dist/tests/comparisons.c (revision 8fa80f29617a57ed2098db654a02cc5c7dc15820)
1 /* comparisons.c -- Comparison functions.
2 
3 Copyright (C) 2008, 2009, 2011 INRIA
4 
5 This file is part of GNU MPC.
6 
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.
11 
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
15 more details.
16 
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/ .
19 */
20 
21 #include "mpc-tests.h"
22 
23 /* comparisons, see description in mpc-tests.h */
24 int
same_mpfr_value(mpfr_ptr got,mpfr_ptr ref,int known_sign)25 same_mpfr_value (mpfr_ptr got, mpfr_ptr ref, int known_sign)
26 {
27    /* The sign of zeroes and infinities is checked only when
28       known_sign is true.                                    */
29    if (mpfr_nan_p (got))
30       return mpfr_nan_p (ref);
31    if (mpfr_inf_p (got))
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;
38 }
39 
40 int
same_mpc_value(mpc_ptr got,mpc_ptr ref,known_signs_t known_signs)41 same_mpc_value (mpc_ptr got, mpc_ptr ref, known_signs_t known_signs)
42 {
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);
45 }
46