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