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