1 /* Test file for mpfr_eq.
3 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
4 Contributed by the AriC and Caramel projects, INRIA.
6 This file is part of the GNU MPFR Library.
8 The GNU MPFR Library is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
13 The GNU MPFR Library is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16 License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
20 http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
21 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
26 #include "mpfr-test.h"
32 unsigned long k, px, mx;
34 mpfr_init2 (y, MPFR_PREC(x));
36 mx = (MPFR_PREC(x) - 1) / mp_bits_per_limb;
37 px = mp_bits_per_limb - 2;
39 for (k = 2; k < MPFR_PREC(x); k++)
41 mpfr_set (y, x, MPFR_RNDN);
43 MPFR_MANT(y) [mx] ^= (mp_limb_t) 1 << px;
45 if (mpfr_eq(y, x, k) || !mpfr_eq(y, x, k - 1))
47 printf ("Error in eq.\n");
48 printf ("x = "); mpfr_print_binary (x); printf ("\n");
49 printf ("y = "); mpfr_print_binary (y); printf ("\n");
50 printf ("k = %lu\n", k);
51 printf ("mpfr_eq(y, x, k) = %d\nmpfr_eq(y, x, k - 1) = %d\n",
52 mpfr_eq (y, x, k), mpfr_eq (y, x, k - 1));
63 px = mp_bits_per_limb - 1;
79 mpfr_set_str (x, "1", 10, (mpfr_rnd_t) 0);
80 mpfr_set_str (y, "1e-10000", 10, (mpfr_rnd_t) 0);
81 mpfr_add (z, x, y, MPFR_RNDU);
83 for (i = 1; i <= 52; i++)
84 if (mpfr_eq (x, z, i) == 0)
86 for (i = 53; i <= 100; i++)
87 if (mpfr_eq (x, z, i) != 0)
89 if (mpfr_eq (x, z, 1000) != 0)
94 printf ("Error in mpfr_eq (1, 1+1e-1000)\n");
100 MPFR_ASSERTN(mpfr_eq (x, y, 1) == 0);
103 MPFR_ASSERTN(mpfr_eq (x, y, 1) == 0);
105 mpfr_set_ui (y, 0, MPFR_RNDN);
106 MPFR_ASSERTN(mpfr_eq (x, y, 1) == 0);
110 MPFR_ASSERTN(mpfr_eq (x, y, 1));
113 mpfr_set_inf (y, -1);
114 MPFR_ASSERTN(mpfr_eq (x, y, 1) == 0);
116 mpfr_set_inf (x, -1);
117 mpfr_set_inf (y, -1);
118 MPFR_ASSERTN(mpfr_eq (x, y, 1));
121 mpfr_set_ui (y, 0, MPFR_RNDN);
122 MPFR_ASSERTN(mpfr_eq (x, y, 1) == 0);
124 mpfr_set_ui (x, 1, MPFR_RNDN);
125 mpfr_set_ui (y, 0, MPFR_RNDN);
126 MPFR_ASSERTN(mpfr_eq (x, y, 1) == 0);
127 MPFR_ASSERTN(mpfr_eq (y, x, 1) == 0);
129 mpfr_set_ui (x, 0, MPFR_RNDN);
130 mpfr_set_ui (y, 0, MPFR_RNDN);
131 MPFR_ASSERTN(mpfr_eq (x, y, 1));
133 mpfr_neg (y, y, MPFR_RNDN);
134 MPFR_ASSERTN(mpfr_eq (x, y, 1));
136 mpfr_neg (x, x, MPFR_RNDN);
137 MPFR_ASSERTN(mpfr_eq (x, y, 1));
139 mpfr_set_ui (x, 1, MPFR_RNDN);
140 mpfr_neg (y, x, MPFR_RNDN);
141 MPFR_ASSERTN(mpfr_eq (x, y, 1) == 0);
143 mpfr_set_prec (x, 2 * mp_bits_per_limb);
144 mpfr_set_prec (y, mp_bits_per_limb);
145 mpfr_set_ui (x, 1, MPFR_RNDN);
146 mpfr_set_ui (y, 1, MPFR_RNDN);
147 MPFR_ASSERTN(mpfr_eq (x, y, mp_bits_per_limb - 1));
148 MPFR_ASSERTN(mpfr_eq (x, y, mp_bits_per_limb));
149 MPFR_ASSERTN(mpfr_eq (x, y, mp_bits_per_limb + 1));
150 MPFR_ASSERTN(mpfr_eq (x, y, 2 * mp_bits_per_limb - 1));
151 MPFR_ASSERTN(mpfr_eq (x, y, 2 * mp_bits_per_limb));
152 MPFR_ASSERTN(mpfr_eq (x, y, 2 * mp_bits_per_limb + 1));
155 MPFR_ASSERTN(mpfr_eq (x, y, mp_bits_per_limb - 1));
156 MPFR_ASSERTN(mpfr_eq (x, y, mp_bits_per_limb));
157 MPFR_ASSERTN(mpfr_eq (x, y, mp_bits_per_limb + 1));
158 MPFR_ASSERTN(mpfr_eq (x, y, 2 * mp_bits_per_limb - 1));
159 MPFR_ASSERTN(mpfr_eq (x, y, 2 * mp_bits_per_limb) == 0);
160 MPFR_ASSERTN(mpfr_eq (x, y, 2 * mp_bits_per_limb + 1) == 0);
161 MPFR_ASSERTN(mpfr_eq (y, x, mp_bits_per_limb - 1));
162 MPFR_ASSERTN(mpfr_eq (y, x, mp_bits_per_limb));
163 MPFR_ASSERTN(mpfr_eq (y, x, mp_bits_per_limb + 1));
164 MPFR_ASSERTN(mpfr_eq (y, x, 2 * mp_bits_per_limb - 1));
165 MPFR_ASSERTN(mpfr_eq (y, x, 2 * mp_bits_per_limb) == 0);
166 MPFR_ASSERTN(mpfr_eq (y, x, 2 * mp_bits_per_limb + 1) == 0);
168 mpfr_set_ui (x, 1, MPFR_RNDN);
169 mpfr_set_ui (y, 2, MPFR_RNDN);
170 MPFR_ASSERTN(mpfr_eq (x, y, 1) == 0);
172 mpfr_set_prec (x, 2 * mp_bits_per_limb);
173 mpfr_set_prec (y, 2 * mp_bits_per_limb);
174 mpfr_set_ui (x, 2, MPFR_RNDN);
175 mpfr_set_ui (y, 3, MPFR_RNDN);
176 MPFR_ASSERTN(mpfr_eq (x, y, 1));
177 MPFR_ASSERTN(mpfr_eq (x, y, 2) == 0);
178 MPFR_ASSERTN(mpfr_eq (x, y, mp_bits_per_limb) == 0);
179 MPFR_ASSERTN(mpfr_eq (x, y, mp_bits_per_limb + 1) == 0);
198 for (j = 0; j < 500; j++)
200 mpfr_urandomb (x, RANDS);