1 /* Test file for mpfr_erf and mpfr_erfc.
2
3 Copyright 2001-2023 Free Software Foundation, Inc.
4 Contributed by the AriC and Caramba projects, INRIA.
5
6 This file is part of the GNU MPFR Library.
7
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.
12
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.
17
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 https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
21 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
22
23 #include "mpfr-test.h"
24
25 #define TEST_FUNCTION mpfr_erf
26 #define test_generic test_generic_erf
27 #include "tgeneric.c"
28
29 #define TEST_FUNCTION mpfr_erfc
30 #undef TEST_RANDOM_EMAX
31 #define TEST_RANDOM_EMAX 63
32 #define test_generic test_generic_erfc
33 #include "tgeneric.c"
34
35 static void
special_erf(void)36 special_erf (void)
37 {
38 mpfr_t x, y;
39 int inex;
40
41 mpfr_init2 (x, 53);
42 mpfr_init2 (y, 53);
43
44 /* erf(NaN) = NaN */
45 mpfr_set_nan (x);
46 mpfr_erf (y, x, MPFR_RNDN);
47 if (!mpfr_nan_p (y))
48 {
49 printf ("mpfr_erf failed for x=NaN\n");
50 exit (1);
51 }
52
53 /* erf(+Inf) = 1 */
54 mpfr_set_inf (x, 1);
55 mpfr_erf (y, x, MPFR_RNDN);
56 if (mpfr_cmp_ui (y, 1))
57 {
58 printf ("mpfr_erf failed for x=+Inf\n");
59 printf ("expected 1.0, got ");
60 mpfr_out_str (stdout, 2, 0, y, MPFR_RNDN);
61 printf ("\n");
62 exit (1);
63 }
64
65 /* erf(-Inf) = -1 */
66 mpfr_set_inf (x, -1);
67 mpfr_erf (y, x, MPFR_RNDN);
68 if (mpfr_cmp_si (y, -1))
69 {
70 printf ("mpfr_erf failed for x=-Inf\n");
71 exit (1);
72 }
73
74 /* erf(+0) = +0 */
75 mpfr_set_ui (x, 0, MPFR_RNDN);
76 mpfr_erf (y, x, MPFR_RNDN);
77 if (MPFR_NOTZERO (y) || MPFR_IS_NEG (y))
78 {
79 printf ("mpfr_erf failed for x=+0\n");
80 exit (1);
81 }
82
83 /* erf(-0) = -0 */
84 mpfr_neg (x, x, MPFR_RNDN);
85 mpfr_erf (y, x, MPFR_RNDN);
86 if (MPFR_NOTZERO (y) || MPFR_IS_POS (y))
87 {
88 printf ("mpfr_erf failed for x=-0\n");
89 exit (1);
90 }
91
92 mpfr_set_ui (x, 1, MPFR_RNDN);
93 mpfr_erf (x, x, MPFR_RNDN);
94 mpfr_set_str_binary (y, "0.11010111101110110011110100111010000010000100010001011");
95 if (mpfr_cmp (x, y))
96 {
97 printf ("mpfr_erf failed for x=1.0, rnd=MPFR_RNDN\n");
98 printf ("expected ");
99 mpfr_out_str (stdout, 2, 0, y, MPFR_RNDN);
100 printf ("\n");
101 printf ("got ");
102 mpfr_out_str (stdout, 2, 0, x, MPFR_RNDN);
103 printf ("\n");
104 exit (1);
105 }
106
107 mpfr_set_str (x, "6.6", 10, MPFR_RNDN);
108 mpfr_erf (x, x, MPFR_RNDN);
109 if (mpfr_cmp_ui (x, 1))
110 {
111 printf ("mpfr_erf failed for x=6.6, rnd=MPFR_RNDN\n");
112 printf ("expected 1\n");
113 printf ("got ");
114 mpfr_out_str (stdout, 2, 0, x, MPFR_RNDN);
115 printf ("\n");
116 exit (1);
117 }
118
119 mpfr_set_str (x, "-6.6", 10, MPFR_RNDN);
120 mpfr_erf (x, x, MPFR_RNDN);
121 if (mpfr_cmp_si (x, -1))
122 {
123 printf ("mpfr_erf failed for x=-6.6, rnd=MPFR_RNDN\n");
124 printf ("expected -1\n");
125 printf ("got ");
126 mpfr_out_str (stdout, 2, 0, x, MPFR_RNDN);
127 printf ("\n");
128 exit (1);
129 }
130
131 mpfr_set_str (x, "6.6", 10, MPFR_RNDN);
132 mpfr_erf (x, x, MPFR_RNDZ);
133 mpfr_set_str_binary (y, "0.11111111111111111111111111111111111111111111111111111");
134 if (mpfr_cmp (x, y))
135 {
136 printf ("mpfr_erf failed for x=6.6, rnd=MPFR_RNDZ\n");
137 printf ("expected ");
138 mpfr_out_str (stdout, 2, 0, y, MPFR_RNDN);
139 printf ("\n");
140 printf ("got ");
141 mpfr_out_str (stdout, 2, 0, x, MPFR_RNDN);
142 printf ("\n");
143 exit (1);
144 }
145
146 mpfr_set_str (x, "4.5", 10, MPFR_RNDN);
147 mpfr_erf (x, x, MPFR_RNDN);
148 mpfr_set_str_binary (y, "0.1111111111111111111111111111111100100111110100011");
149 if (mpfr_cmp (x, y))
150 {
151 printf ("mpfr_erf failed for x=4.5, rnd=MPFR_RNDN\n");
152 printf ("expected ");
153 mpfr_out_str (stdout, 2, 0, y, MPFR_RNDN);
154 printf ("\n");
155 printf ("got ");
156 mpfr_out_str (stdout, 2, 0, x, MPFR_RNDN);
157 printf ("\n");
158 exit (1);
159 }
160
161 mpfr_set_prec (x, 120);
162 mpfr_set_prec (y, 120);
163 mpfr_set_str_binary (x, "0.110100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011E3");
164 mpfr_erf (x, x, MPFR_RNDN);
165 mpfr_set_str_binary (y, "0.11111111111111111111111111111111111111111111111111111111111111111100111111000100111011111011010000110101111100011001101");
166 if (mpfr_cmp (x, y))
167 {
168 printf ("mpfr_erf failed for x=6.6, rnd=MPFR_RNDN\n");
169 printf ("expected ");
170 mpfr_out_str (stdout, 2, 0, y, MPFR_RNDN);
171 printf ("\n");
172 printf ("got ");
173 mpfr_out_str (stdout, 2, 0, x, MPFR_RNDN);
174 printf ("\n");
175 exit (1);
176 }
177
178 mpfr_set_prec (x, 8);
179 mpfr_set_prec (y, 8);
180 mpfr_set_ui (x, 50, MPFR_RNDN);
181 inex = mpfr_erf (y, x, MPFR_RNDN);
182 if (mpfr_cmp_ui (y, 1))
183 {
184 printf ("mpfr_erf failed for x=50, rnd=MPFR_RNDN\n");
185 printf ("expected 1, got ");
186 mpfr_out_str (stdout, 2, 0, y, MPFR_RNDN);
187 printf ("\n");
188 exit (1);
189 }
190 if (inex <= 0)
191 {
192 printf ("mpfr_erf failed for x=50, rnd=MPFR_RNDN: wrong ternary value\n"
193 "expected positive, got %d\n", inex);
194 exit (1);
195 }
196 inex = mpfr_erf (x, x, MPFR_RNDZ);
197 mpfr_nextbelow (y);
198 if (mpfr_cmp (x, y))
199 {
200 printf ("mpfr_erf failed for x=50, rnd=MPFR_RNDZ\n");
201 printf ("expected ");
202 mpfr_out_str (stdout, 2, 0, y, MPFR_RNDN);
203 printf ("\n");
204 printf ("got ");
205 mpfr_out_str (stdout, 2, 0, x, MPFR_RNDN);
206 printf ("\n");
207 exit (1);
208 }
209 if (inex >= 0)
210 {
211 printf ("mpfr_erf failed for x=50, rnd=MPFR_RNDN: wrong ternary value\n"
212 "expected negative, got %d\n", inex);
213 exit (1);
214 }
215
216 mpfr_set_prec (x, 32);
217 mpfr_set_prec (y, 32);
218
219 mpfr_set_str_binary (x, "0.1010100100111011001111100101E-1");
220 mpfr_set_str_binary (y, "0.10111000001110011010110001101011E-1");
221 mpfr_erf (x, x, MPFR_RNDN);
222 if (mpfr_cmp (x, y))
223 {
224 printf ("Error: erf for prec=32 (1)\n");
225 exit (1);
226 }
227
228 mpfr_set_str_binary (x, "-0.10110011011010111110010001100001");
229 mpfr_set_str_binary (y, "-0.1010110110101011100010111000111");
230 mpfr_erf (x, x, MPFR_RNDN);
231 if (mpfr_cmp (x, y))
232 {
233 printf ("Error: erf for prec=32 (2)\n");
234 mpfr_dump (x);
235 exit (1);
236 }
237
238 mpfr_set_str_binary (x, "100.10001110011110100000110000111");
239 mpfr_set_str_binary (y, "0.11111111111111111111111111111111");
240 mpfr_erf (x, x, MPFR_RNDN);
241 if (mpfr_cmp (x, y))
242 {
243 printf ("Error: erf for prec=32 (3)\n");
244 exit (1);
245 }
246 mpfr_set_str_binary (x, "100.10001110011110100000110000111");
247 mpfr_erf (x, x, MPFR_RNDZ);
248 if (mpfr_cmp (x, y))
249 {
250 printf ("Error: erf for prec=32 (4)\n");
251 exit (1);
252 }
253 mpfr_set_str_binary (x, "100.10001110011110100000110000111");
254 mpfr_erf (x, x, MPFR_RNDU);
255 if (mpfr_cmp_ui (x, 1))
256 {
257 printf ("Error: erf for prec=32 (5)\n");
258 exit (1);
259 }
260
261 mpfr_set_str_binary (x, "100.10001110011110100000110001000");
262 mpfr_erf (x, x, MPFR_RNDN);
263 if (mpfr_cmp_ui (x, 1))
264 {
265 printf ("Error: erf for prec=32 (6)\n");
266 exit (1);
267 }
268 mpfr_set_str_binary (x, "100.10001110011110100000110001000");
269 mpfr_set_str_binary (y, "0.11111111111111111111111111111111");
270 mpfr_erf (x, x, MPFR_RNDZ);
271 if (mpfr_cmp (x, y))
272 {
273 printf ("Error: erf for prec=32 (7)\n");
274 exit (1);
275 }
276 mpfr_set_str_binary (x, "100.10001110011110100000110001000");
277 mpfr_erf (x, x, MPFR_RNDU);
278 if (mpfr_cmp_ui (x, 1))
279 {
280 printf ("Error: erf for prec=32 (8)\n");
281 exit (1);
282 }
283
284 mpfr_set_ui (x, 5, MPFR_RNDN);
285 mpfr_erf (x, x, MPFR_RNDN);
286 if (mpfr_cmp_ui (x, 1))
287 {
288 printf ("Error: erf for prec=32 (9)\n");
289 exit (1);
290 }
291 mpfr_set_ui (x, 5, MPFR_RNDN);
292 mpfr_erf (x, x, MPFR_RNDU);
293 if (mpfr_cmp_ui (x, 1))
294 {
295 printf ("Error: erf for prec=32 (10)\n");
296 exit (1);
297 }
298 mpfr_set_ui (x, 5, MPFR_RNDN);
299 mpfr_erf (x, x, MPFR_RNDZ);
300 mpfr_set_str_binary (y, "0.11111111111111111111111111111111");
301 if (mpfr_cmp (x, y))
302 {
303 printf ("Error: erf for prec=32 (11)\n");
304 exit (1);
305 }
306 mpfr_set_ui (x, 5, MPFR_RNDN);
307 mpfr_erf (x, x, MPFR_RNDD);
308 mpfr_set_str_binary (y, "0.11111111111111111111111111111111");
309 if (mpfr_cmp (x, y))
310 {
311 printf ("Error: erf for prec=32 (12)\n");
312 exit (1);
313 }
314
315 mpfr_set_prec (x, 43);
316 mpfr_set_prec (y, 64);
317 mpfr_set_str_binary (x, "-0.1101110110101111100101011101110101101001001e3");
318 mpfr_erf (y, x, MPFR_RNDU);
319 mpfr_set_prec (x, 64);
320 mpfr_set_str_binary (x, "-0.1111111111111111111111111111111111111111111111111111111111111111");
321 if (mpfr_cmp (x, y))
322 {
323 printf ("Error: erf for prec=43,64 (13)\n");
324 exit (1);
325 }
326
327 /* worst cases */
328 mpfr_set_prec (x, 53);
329 mpfr_set_prec (y, 53);
330 mpfr_set_str_binary (x, "1.0000000000000000000000000000000000000110000000101101");
331 mpfr_erf (y, x, MPFR_RNDN);
332 mpfr_set_str_binary (x, "0.110101111011101100111101001110100000101011000011001");
333 if (mpfr_cmp (x, y))
334 {
335 printf ("Error: erf for worst case (1)\n");
336 exit (1);
337 }
338
339 mpfr_set_str_binary (x, "1.0000000000000000000000000000011000111010101101011010");
340 mpfr_erf (y, x, MPFR_RNDU);
341 mpfr_set_str_binary (x, "0.11010111101110110011110100111100100111100011111000110");
342 if (mpfr_cmp (x, y))
343 {
344 printf ("Error: erf for worst case (2a)\n");
345 exit (1);
346 }
347 mpfr_set_str_binary (x, "1.0000000000000000000000000000011000111010101101011010");
348 mpfr_erf (y, x, MPFR_RNDD);
349 mpfr_set_str_binary (x, "0.11010111101110110011110100111100100111100011111000101");
350 if (mpfr_cmp (x, y))
351 {
352 printf ("Error: erf for worst case (2b)\n");
353 exit (1);
354 }
355
356 mpfr_clear (x);
357 mpfr_clear (y);
358 }
359
360 static void
special_erfc(void)361 special_erfc (void)
362 {
363 mpfr_t x, y;
364
365 mpfr_inits (x, y, (mpfr_ptr) 0);
366
367 /* erfc (NaN) = NaN */
368 mpfr_set_nan (x);
369 mpfr_erfc (y, x, MPFR_RNDN);
370 if (!mpfr_nan_p (y))
371 {
372 printf ("mpfr_erfc failed for x=NaN\n");
373 exit (1);
374 }
375 /* erfc(+Inf) = 0+ */
376 mpfr_set_inf (x, 1);
377 mpfr_erfc (y, x, MPFR_RNDN);
378 if (!MPFR_IS_ZERO (y) || !MPFR_IS_POS (y))
379 {
380 printf ("mpfr_erf failed for x=+Inf\n");
381 printf ("expected 0+, got ");
382 mpfr_dump (y);
383 exit (1);
384 }
385 /* erfc(-Inf) = 2 */
386 mpfr_set_inf (x, -1);
387 mpfr_erfc (y, x, MPFR_RNDN);
388 if (mpfr_cmp_ui (y, 2))
389 {
390 printf ("mpfr_erf failed for x=-Inf\n");
391 printf ("expected 2, got ");
392 mpfr_dump (y);
393 exit (1);
394 }
395 /* erf(+0) = 1 */
396 mpfr_set_ui (x, 0, MPFR_RNDN);
397 mpfr_erfc (y, x, MPFR_RNDN);
398 if (mpfr_cmp_ui (y, 1))
399 {
400 printf ("mpfr_erf failed for x=+0\n");
401 printf ("expected 1, got ");
402 mpfr_dump (y);
403 exit (1);
404 }
405
406 mpfr_clears (x, y, (mpfr_ptr) 0);
407 }
408
409 static void
large_arg(void)410 large_arg (void)
411 {
412 mpfr_t x, y;
413 unsigned int flags;
414
415 mpfr_init2 (x, 88);
416 mpfr_init2 (y, 98);
417
418 mpfr_set_si_2exp (x, -1, 173, MPFR_RNDN);
419 mpfr_clear_flags ();
420 mpfr_erfc (y, x, MPFR_RNDN);
421 flags = __gmpfr_flags;
422 if (mpfr_cmp_ui (y, 2) != 0)
423 {
424 printf ("mpfr_erfc failed for large x (1)\n");
425 exit (1);
426 }
427 if (flags != MPFR_FLAGS_INEXACT)
428 {
429 printf ("mpfr_erfc sets incorrect flags for large x (1)\n");
430 printf ("Expected %u, got %u\n",
431 (unsigned int) MPFR_FLAGS_INEXACT, flags);
432 exit (1);
433 }
434
435 mpfr_set_si_2exp (x, -1, mpfr_get_emax () - 3, MPFR_RNDN);
436 mpfr_clear_flags ();
437 mpfr_erfc (y, x, MPFR_RNDN);
438 flags = __gmpfr_flags;
439 if (mpfr_cmp_ui (y, 2) != 0)
440 {
441 printf ("mpfr_erfc failed for large x (1b)\n");
442 exit (1);
443 }
444 if (flags != MPFR_FLAGS_INEXACT)
445 {
446 printf ("mpfr_erfc sets incorrect flags for large x (1b)\n");
447 printf ("Expected %u, got %u\n",
448 (unsigned int) MPFR_FLAGS_INEXACT, flags);
449 exit (1);
450 }
451
452 mpfr_set_prec (x, 33);
453 mpfr_set_prec (y, 43);
454 mpfr_set_str_binary (x, "1.11000101010111011000111100101001e6");
455 mpfr_erfc (y, x, MPFR_RNDD);
456 mpfr_set_prec (x, 43);
457 mpfr_set_str_binary (x, "100010011100101100001101100101011101101E-18579");
458 if (mpfr_cmp (x, y) != 0)
459 {
460 printf ("mpfr_erfc failed for large x (2)\n");
461 exit (1);
462 }
463
464 mpfr_set_prec (y, 43);
465 mpfr_set_si_2exp (x, 1, 11, MPFR_RNDN);
466 mpfr_erfc (y, x, MPFR_RNDN);
467 mpfr_set_str_binary (x, "0.1100000100100010101111001111010010001000110E-6051113");
468 if (mpfr_cmp (x, y) != 0)
469 {
470 printf ("mpfr_erfc failed for large x (3)\n");
471 exit (1);
472 }
473
474 mpfr_set_prec (x, 75);
475 mpfr_set_prec (y, 85);
476 mpfr_set_str_binary (x, "0.111110111111010011101011001100001010011110101010011111010010111101010001011E15");
477 mpfr_erfc (y, x, MPFR_RNDN);
478 if (MPFR_NOTZERO (y) || MPFR_IS_NEG (y))
479 {
480 printf ("mpfr_erfc failed for large x (3b)\n");
481 exit (1);
482 }
483
484 mpfr_set_prec (x, 2);
485 mpfr_set_prec (y, 21);
486 mpfr_set_str_binary (x, "-1.0e3");
487 mpfr_clear_flags ();
488 mpfr_erfc (y, x, MPFR_RNDZ);
489 flags = __gmpfr_flags;
490 mpfr_set_prec (x, 21);
491 mpfr_set_str_binary (x, "1.11111111111111111111");
492 if (mpfr_cmp (x, y) != 0)
493 {
494 printf ("mpfr_erfc failed for large x (4)\n");
495 exit (1);
496 }
497 if (flags != MPFR_FLAGS_INEXACT)
498 {
499 printf ("mpfr_erfc sets incorrect flags for large x (4)\n");
500 printf ("Expected %u, got %u\n",
501 (unsigned int) MPFR_FLAGS_INEXACT, flags);
502 exit (1);
503 }
504
505 mpfr_set_prec (x, 2);
506 mpfr_set_prec (y, 31);
507 mpfr_set_str_binary (x, "-1.0e3");
508 mpfr_clear_flags ();
509 mpfr_erfc (y, x, MPFR_RNDZ);
510 flags = __gmpfr_flags;
511 mpfr_set_prec (x, 31);
512 mpfr_set_str_binary (x, "1.111111111111111111111111111111");
513 if (mpfr_cmp (x, y) != 0)
514 {
515 printf ("mpfr_erfc failed for x=-8, prec=31 (5)\n");
516 printf ("expected "); mpfr_dump (x);
517 printf ("got "); mpfr_dump (y);
518 exit (1);
519 }
520 if (flags != MPFR_FLAGS_INEXACT)
521 {
522 printf ("mpfr_erfc sets incorrect flags for large x (5)\n");
523 printf ("Expected %u, got %u\n",
524 (unsigned int) MPFR_FLAGS_INEXACT, flags);
525 exit (1);
526 }
527
528 /* Reported by Christopher Creutzig on 2007-07-10. */
529 mpfr_set_prec (x, 53);
530 mpfr_set_prec (y, 53);
531 mpfr_set_si_2exp (x, 54563, -1, MPFR_RNDN);
532 mpfr_erfc (y, x, MPFR_RNDZ);
533 mpfr_set_ui (x, 0, MPFR_RNDN);
534 if (! mpfr_equal_p (y, x))
535 {
536 printf ("mpfr_erfc failed for x=27281.5, prec=53 (6)\n");
537 printf ("expected "); mpfr_dump (x);
538 printf ("got "); mpfr_dump (y);
539 exit (1);
540 }
541
542 /* same test with rounding away from zero */
543 mpfr_set_si_2exp (x, 54563, -1, MPFR_RNDN);
544 mpfr_erfc (y, x, MPFR_RNDU);
545 mpfr_set_ui (x, 0, MPFR_RNDN);
546 mpfr_nextabove (x);
547 if (! mpfr_equal_p (y, x))
548 {
549 printf ("mpfr_erfc failed for x=27281.5, prec=53 (7)\n");
550 printf ("expected "); mpfr_dump (x);
551 printf ("got "); mpfr_dump (y);
552 exit (1);
553 }
554
555 mpfr_clear (x);
556 mpfr_clear (y);
557 }
558
559 static void
test_erfc(void)560 test_erfc (void)
561 {
562 mpfr_t x, y, z;
563 int inex;
564 mpfr_exp_t emin;
565
566 mpfr_inits2 (40, x, y, z, (mpfr_ptr) 0);
567
568 mpfr_set_si_2exp (x, -1, -10, MPFR_RNDN);
569 mpfr_set_str_binary (z, "0.1000000000100100000110111010110111100000E1");
570 mpfr_erfc (y, x, MPFR_RNDN);
571 if (mpfr_cmp (y, z) != 0)
572 {
573 printf ("mpfr_erfc failed for x = ");
574 mpfr_dump (x);
575 printf ("got ");
576 mpfr_dump (y);
577 printf ("instead of ");
578 mpfr_dump (z);
579 exit (1);
580 }
581
582 /* slowness detected by Kevin Rauch on 26 Oct 2007 */
583 mpfr_set_prec (x, 128);
584 mpfr_set_si (x, -256, MPFR_RNDN);
585 inex = mpfr_erfc (x, x, MPFR_RNDN);
586 MPFR_ASSERTN(inex > 0 && mpfr_cmp_ui (x, 2) == 0);
587
588 /* bug found by Pascal Molin on March 10, 2011 */
589 emin = mpfr_get_emin ();
590 if (! mpfr_set_emin (-1073808789))
591 {
592 /* Typically, a 64-bit machine. */
593 mpfr_set_si (x, 27282, MPFR_RNDN);
594 mpfr_erfc (y, x, MPFR_RNDN);
595 MPFR_ASSERTN(mpfr_cmp_ui (y, 0) != 0);
596 set_emin (emin);
597 }
598
599 mpfr_clears (x, y, z, (mpfr_ptr) 0);
600 }
601
602 /* Failure in r7569 (2011-03-15) due to incorrect flags. */
603 static void
reduced_expo_range(void)604 reduced_expo_range (void)
605 {
606 mpfr_exp_t emax;
607 mpfr_t x, y, ex_y;
608 int inex, ex_inex;
609 unsigned int flags, ex_flags;
610
611 emax = mpfr_get_emax ();
612 set_emax (3);
613 mpfr_init2 (x, 33);
614 mpfr_inits2 (110, y, ex_y, (mpfr_ptr) 0);
615 mpfr_set_str_binary (x, "-0.111100110111111111011101010101110E3");
616 mpfr_clear_flags ();
617 inex = mpfr_erfc (y, x, MPFR_RNDZ);
618 flags = __gmpfr_flags;
619 mpfr_set_str (ex_y, "1.fffffffffffffffffffffe607440", 16, MPFR_RNDN);
620 ex_inex = -1;
621 ex_flags = MPFR_FLAGS_INEXACT;
622 if (VSIGN (inex) != ex_inex || flags != ex_flags ||
623 ! mpfr_equal_p (y, ex_y))
624 {
625 printf ("Error in reduced_expo_range\non x = ");
626 mpfr_dump (x);
627 printf ("Expected y = ");
628 mpfr_out_str (stdout, 16, 0, ex_y, MPFR_RNDN);
629 printf ("\n inex = %d, flags = %u\n", ex_inex, ex_flags);
630 printf ("Got y = ");
631 mpfr_out_str (stdout, 16, 0, y, MPFR_RNDN);
632 printf ("\n inex = %d, flags = %u\n", VSIGN (inex), flags);
633 exit (1);
634 }
635 mpfr_clears (x, y, ex_y, (mpfr_ptr) 0);
636 set_emax (emax);
637 }
638
639 /* Similar to a bug reported by Naoki Shibata:
640 https://sympa.inria.fr/sympa/arc/mpfr/2018-07/msg00028.html
641 */
642 static void
bug20180723(void)643 bug20180723 (void)
644 {
645 mpfr_t x;
646
647 mpfr_init2 (x, 256);
648 mpfr_set_ui (x, 28, MPFR_RNDN);
649 mpfr_erfc (x, x, MPFR_RNDN);
650 mpfr_clear (x);
651 }
652
653 int
main(int argc,char * argv[])654 main (int argc, char *argv[])
655 {
656 tests_start_mpfr ();
657
658 special_erf ();
659 special_erfc ();
660 large_arg ();
661 test_erfc ();
662 reduced_expo_range ();
663 bug20180723 ();
664
665 test_generic_erf (MPFR_PREC_MIN, 300, 150);
666 test_generic_erfc (MPFR_PREC_MIN, 300, 150);
667
668 data_check ("data/erf", mpfr_erf, "mpfr_erf");
669 data_check ("data/erfc", mpfr_erfc, "mpfr_erfc");
670
671 tests_end_mpfr ();
672 return 0;
673 }
674