1
/* Test file for mpfr_erf.
3
Copyright 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4
Contributed by Ludovic Meunier and Paul Zimmermann.
6
This file is part of the MPFR Library.
8
The 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 2.1 of the License, or (at your
11
option) any later version.
13
The 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 MPFR Library; see the file COPYING.LIB. If not, write to
20
the Free Software Foundation, Inc., 51 Franklin Place, Fifth Floor, Boston,
21
MA 02110-1301, USA. */
27
#include "mpfr-test.h"
29
#define TEST_FUNCTION mpfr_erf
30
#define test_generic test_generic_erf
33
#define TEST_FUNCTION mpfr_erfc
34
#define test_generic test_generic_erfc
48
mpfr_erf (y, x, GMP_RNDN);
51
printf ("mpfr_erf failed for x=NaN\n");
57
mpfr_erf (y, x, GMP_RNDN);
58
if (mpfr_cmp_ui (y, 1))
60
printf ("mpfr_erf failed for x=+Inf\n");
61
printf ("expected 1.0, got ");
62
mpfr_out_str (stdout, 2, 0, y, GMP_RNDN);
69
mpfr_erf (y, x, GMP_RNDN);
70
if (mpfr_cmp_si (y, -1))
72
printf ("mpfr_erf failed for x=-Inf\n");
77
mpfr_set_ui (x, 0, GMP_RNDN);
78
mpfr_erf (y, x, GMP_RNDN);
79
if (mpfr_cmp_ui (y, 0) || mpfr_sgn (y) < 0)
81
printf ("mpfr_erf failed for x=+0\n");
86
mpfr_neg (x, x, GMP_RNDN);
87
mpfr_erf (y, x, GMP_RNDN);
88
if (mpfr_cmp_ui (y, 0) || mpfr_sgn (y) > 0)
90
printf ("mpfr_erf failed for x=-0\n");
94
mpfr_set_ui (x, 1, GMP_RNDN);
95
mpfr_erf (x, x, GMP_RNDN);
96
mpfr_set_str_binary (y, "0.11010111101110110011110100111010000010000100010001011");
99
printf ("mpfr_erf failed for x=1.0, rnd=GMP_RNDN\n");
100
printf ("expected ");
101
mpfr_out_str (stdout, 2, 0, y, GMP_RNDN);
104
mpfr_out_str (stdout, 2, 0, x, GMP_RNDN);
109
mpfr_set_str (x, "6.6", 10, GMP_RNDN);
110
mpfr_erf (x, x, GMP_RNDN);
111
if (mpfr_cmp_ui (x, 1))
113
printf ("mpfr_erf failed for x=6.6, rnd=GMP_RNDN\n");
114
printf ("expected 1\n");
116
mpfr_out_str (stdout, 2, 0, x, GMP_RNDN);
121
mpfr_set_str (x, "-6.6", 10, GMP_RNDN);
122
mpfr_erf (x, x, GMP_RNDN);
123
if (mpfr_cmp_si (x, -1))
125
printf ("mpfr_erf failed for x=-6.6, rnd=GMP_RNDN\n");
126
printf ("expected -1\n");
128
mpfr_out_str (stdout, 2, 0, x, GMP_RNDN);
133
mpfr_set_str (x, "6.6", 10, GMP_RNDN);
134
mpfr_erf (x, x, GMP_RNDZ);
135
mpfr_set_str_binary (y, "0.11111111111111111111111111111111111111111111111111111");
138
printf ("mpfr_erf failed for x=6.6, rnd=GMP_RNDZ\n");
139
printf ("expected ");
140
mpfr_out_str (stdout, 2, 0, y, GMP_RNDN);
143
mpfr_out_str (stdout, 2, 0, x, GMP_RNDN);
148
mpfr_set_str (x, "4.5", 10, GMP_RNDN);
149
mpfr_erf (x, x, GMP_RNDN);
150
mpfr_set_str_binary (y, "0.1111111111111111111111111111111100100111110100011");
153
printf ("mpfr_erf failed for x=4.5, rnd=GMP_RNDN\n");
154
printf ("expected ");
155
mpfr_out_str (stdout, 2, 0, y, GMP_RNDN);
158
mpfr_out_str (stdout, 2, 0, x, GMP_RNDN);
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, GMP_RNDN);
167
mpfr_set_str_binary (y, "0.11111111111111111111111111111111111111111111111111111111111111111100111111000100111011111011010000110101111100011001101");
170
printf ("mpfr_erf failed for x=6.6, rnd=GMP_RNDN\n");
171
printf ("expected ");
172
mpfr_out_str (stdout, 2, 0, y, GMP_RNDN);
175
mpfr_out_str (stdout, 2, 0, x, GMP_RNDN);
180
mpfr_set_prec (x, 8);
181
mpfr_set_prec (y, 8);
182
mpfr_set_ui (x, 50, GMP_RNDN);
183
inex = mpfr_erf (y, x, GMP_RNDN);
184
if (mpfr_cmp_ui (y, 1))
186
printf ("mpfr_erf failed for x=50, rnd=GMP_RNDN\n");
187
printf ("expected 1, got ");
188
mpfr_out_str (stdout, 2, 0, y, GMP_RNDN);
194
printf ("mpfr_erf failed for x=50, rnd=GMP_RNDN: wrong ternary value\n"
195
"expected positive, got %d\n", inex);
198
inex = mpfr_erf (x, x, GMP_RNDZ);
202
printf ("mpfr_erf failed for x=50, rnd=GMP_RNDZ\n");
203
printf ("expected ");
204
mpfr_out_str (stdout, 2, 0, y, GMP_RNDN);
207
mpfr_out_str (stdout, 2, 0, x, GMP_RNDN);
213
printf ("mpfr_erf failed for x=50, rnd=GMP_RNDN: wrong ternary value\n"
214
"expected negative, got %d\n", inex);
218
mpfr_set_prec (x, 32);
219
mpfr_set_prec (y, 32);
221
mpfr_set_str_binary (x, "0.1010100100111011001111100101E-1");
222
mpfr_set_str_binary (y, "0.10111000001110011010110001101011E-1");
223
mpfr_erf (x, x, GMP_RNDN);
226
printf ("Error: erf for prec=32 (1)\n");
230
mpfr_set_str_binary (x, "-0.10110011011010111110010001100001");
231
mpfr_set_str_binary (y, "-0.1010110110101011100010111000111");
232
mpfr_erf (x, x, GMP_RNDN);
235
printf ("Error: erf for prec=32 (2)\n");
236
mpfr_print_binary (x); printf ("\n");
240
mpfr_set_str_binary (x, "100.10001110011110100000110000111");
241
mpfr_set_str_binary (y, "0.11111111111111111111111111111111");
242
mpfr_erf (x, x, GMP_RNDN);
245
printf ("Error: erf for prec=32 (3)\n");
248
mpfr_set_str_binary (x, "100.10001110011110100000110000111");
249
mpfr_erf (x, x, GMP_RNDZ);
252
printf ("Error: erf for prec=32 (4)\n");
255
mpfr_set_str_binary (x, "100.10001110011110100000110000111");
256
mpfr_erf (x, x, GMP_RNDU);
257
if (mpfr_cmp_ui (x, 1))
259
printf ("Error: erf for prec=32 (5)\n");
263
mpfr_set_str_binary (x, "100.10001110011110100000110001000");
264
mpfr_erf (x, x, GMP_RNDN);
265
if (mpfr_cmp_ui (x, 1))
267
printf ("Error: erf for prec=32 (6)\n");
270
mpfr_set_str_binary (x, "100.10001110011110100000110001000");
271
mpfr_set_str_binary (y, "0.11111111111111111111111111111111");
272
mpfr_erf (x, x, GMP_RNDZ);
275
printf ("Error: erf for prec=32 (7)\n");
278
mpfr_set_str_binary (x, "100.10001110011110100000110001000");
279
mpfr_erf (x, x, GMP_RNDU);
280
if (mpfr_cmp_ui (x, 1))
282
printf ("Error: erf for prec=32 (8)\n");
286
mpfr_set_ui (x, 5, GMP_RNDN);
287
mpfr_erf (x, x, GMP_RNDN);
288
if (mpfr_cmp_ui (x, 1))
290
printf ("Error: erf for prec=32 (9)\n");
293
mpfr_set_ui (x, 5, GMP_RNDN);
294
mpfr_erf (x, x, GMP_RNDU);
295
if (mpfr_cmp_ui (x, 1))
297
printf ("Error: erf for prec=32 (10)\n");
300
mpfr_set_ui (x, 5, GMP_RNDN);
301
mpfr_erf (x, x, GMP_RNDZ);
302
mpfr_set_str_binary (y, "0.11111111111111111111111111111111");
305
printf ("Error: erf for prec=32 (11)\n");
308
mpfr_set_ui (x, 5, GMP_RNDN);
309
mpfr_erf (x, x, GMP_RNDD);
310
mpfr_set_str_binary (y, "0.11111111111111111111111111111111");
313
printf ("Error: erf for prec=32 (12)\n");
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, GMP_RNDU);
321
mpfr_set_prec (x, 64);
322
mpfr_set_str_binary (x, "-0.1111111111111111111111111111111111111111111111111111111111111111");
325
printf ("Error: erf for prec=43,64 (13)\n");
339
mpfr_inits (x, y, NULL);
341
/* erfc (NaN) = NaN */
343
mpfr_erfc (y, x, GMP_RNDN);
346
printf ("mpfr_erfc failed for x=NaN\n");
349
/* erfc(+Inf) = 0+ */
351
mpfr_erfc (y, x, GMP_RNDN);
352
if (!MPFR_IS_ZERO (y) || !MPFR_IS_POS (y))
354
printf ("mpfr_erf failed for x=+Inf\n");
355
printf ("expected 0+, got ");
360
mpfr_set_inf (x, -1);
361
mpfr_erfc (y, x, GMP_RNDN);
362
if (mpfr_cmp_ui (y, 2))
364
printf ("mpfr_erf failed for x=-Inf\n");
365
printf ("expected 2, got ");
370
mpfr_set_ui (x, 0, GMP_RNDN);
371
mpfr_erfc (y, x, GMP_RNDN);
372
if (mpfr_cmp_ui (y, 1))
374
printf ("mpfr_erf failed for x=+0\n");
375
printf ("expected 1, got ");
380
mpfr_clears (x, y, NULL);
384
main (int argc, char *argv[])
391
test_generic_erf (2, 100, 15);
392
test_generic_erfc (2, 100, 15);