1 /* Test file for mpfr_pow, mpfr_pow_ui and mpfr_pow_si. 2 3 Copyright 2000-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 <float.h> 24 #include <math.h> 25 26 #define _MPFR_NO_DEPRECATED_ROOT 27 #include "mpfr-test.h" 28 29 #ifdef CHECK_EXTERNAL 30 static int 31 test_pow (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) 32 { 33 int res; 34 int ok = rnd_mode == MPFR_RNDN && mpfr_number_p (b) && mpfr_number_p (c) 35 && mpfr_get_prec (a) >= 53; 36 if (ok) 37 { 38 mpfr_print_raw (b); 39 printf (" "); 40 mpfr_print_raw (c); 41 } 42 res = mpfr_pow (a, b, c, rnd_mode); 43 if (ok) 44 { 45 printf (" "); 46 mpfr_print_raw (a); 47 printf ("\n"); 48 } 49 return res; 50 } 51 #else 52 #define test_pow mpfr_pow 53 #endif 54 55 #define TEST_FUNCTION test_pow 56 #define TWO_ARGS 57 #define TEST_RANDOM_POS 16 /* the 2nd argument is negative with prob. 16/512 */ 58 #define TGENERIC_NOWARNING 1 59 #include "tgeneric.c" 60 61 #define TEST_FUNCTION mpfr_pow_ui 62 #define INTEGER_TYPE unsigned long 63 #define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1, RANDS) 64 #include "tgeneric_ui.c" 65 66 #define TEST_FUNCTION mpfr_pow_si 67 #define INTEGER_TYPE long 68 #define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1, RANDS) 69 #define test_generic_ui test_generic_si 70 #include "tgeneric_ui.c" 71 72 #define DEFN(N) \ 73 static int powu##N (mpfr_ptr y, mpfr_srcptr x, mpfr_rnd_t rnd) \ 74 { return mpfr_pow_ui (y, x, N, rnd); } \ 75 static int pows##N (mpfr_ptr y, mpfr_srcptr x, mpfr_rnd_t rnd) \ 76 { return mpfr_pow_si (y, x, N, rnd); } \ 77 static int root##N (mpfr_ptr y, mpfr_srcptr x, mpfr_rnd_t rnd) \ 78 { return mpfr_root (y, x, N, rnd); } 79 80 DEFN(2) 81 DEFN(3) 82 DEFN(4) 83 DEFN(5) 84 DEFN(17) 85 DEFN(120) 86 87 static void 88 check_pow_ui (void) 89 { 90 mpfr_t a, b; 91 unsigned long n; 92 int res; 93 94 mpfr_init2 (a, 53); 95 mpfr_init2 (b, 53); 96 97 /* check in-place operations */ 98 mpfr_set_str (b, "0.6926773", 10, MPFR_RNDN); 99 mpfr_pow_ui (a, b, 10, MPFR_RNDN); 100 mpfr_pow_ui (b, b, 10, MPFR_RNDN); 101 if (mpfr_cmp (a, b)) 102 { 103 printf ("Error for mpfr_pow_ui (b, b, ...)\n"); 104 exit (1); 105 } 106 107 /* check large exponents */ 108 mpfr_set_ui (b, 1, MPFR_RNDN); 109 mpfr_pow_ui (a, b, 4294967295UL, MPFR_RNDN); 110 111 mpfr_set_inf (a, -1); 112 mpfr_pow_ui (a, a, 4049053855UL, MPFR_RNDN); 113 if (!mpfr_inf_p (a) || (mpfr_sgn (a) >= 0)) 114 { 115 printf ("Error for (-Inf)^4049053855\n"); 116 exit (1); 117 } 118 119 mpfr_set_inf (a, -1); 120 mpfr_pow_ui (a, a, (unsigned long) 30002752, MPFR_RNDN); 121 if (!mpfr_inf_p (a) || (mpfr_sgn (a) <= 0)) 122 { 123 printf ("Error for (-Inf)^30002752\n"); 124 exit (1); 125 } 126 127 /* Check underflow */ 128 mpfr_set_str_binary (a, "1E-1"); 129 res = mpfr_pow_ui (a, a, -mpfr_get_emin (), MPFR_RNDN); 130 if (MPFR_GET_EXP (a) != mpfr_get_emin () + 1) 131 { 132 printf ("Error for (1e-1)^MPFR_EMAX_MAX\n"); 133 mpfr_dump (a); 134 exit (1); 135 } 136 137 mpfr_set_str_binary (a, "1E-10"); 138 res = mpfr_pow_ui (a, a, -mpfr_get_emin (), MPFR_RNDZ); 139 if (!MPFR_IS_ZERO (a)) 140 { 141 printf ("Error for (1e-10)^MPFR_EMAX_MAX\n"); 142 mpfr_dump (a); 143 exit (1); 144 } 145 146 /* Check overflow */ 147 mpfr_set_str_binary (a, "1E10"); 148 res = mpfr_pow_ui (a, a, ULONG_MAX, MPFR_RNDN); 149 if (!MPFR_IS_INF (a) || MPFR_IS_NEG (a)) 150 { 151 printf ("Error for (1e10)^ULONG_MAX\n"); 152 exit (1); 153 } 154 155 /* Bug in pow_ui.c from r3214 to r5107: if x = y (same mpfr_t argument), 156 the input argument is negative, n is odd, an overflow or underflow 157 occurs, and the temporary result res is positive, then the result 158 gets a wrong sign (positive instead of negative). */ 159 mpfr_set_str_binary (a, "-1E10"); 160 n = (ULONG_MAX ^ (ULONG_MAX >> 1)) + 1; 161 res = mpfr_pow_ui (a, a, n, MPFR_RNDN); 162 if (!MPFR_IS_INF (a) || MPFR_IS_POS (a)) 163 { 164 printf ("Error for (-1e10)^%lu, expected -Inf,\ngot ", n); 165 mpfr_dump (a); 166 exit (1); 167 } 168 169 /* Check 0 */ 170 MPFR_SET_ZERO (a); 171 MPFR_SET_POS (a); 172 mpfr_set_si (b, -1, MPFR_RNDN); 173 res = mpfr_pow_ui (b, a, 1, MPFR_RNDN); 174 if (res != 0 || MPFR_IS_NEG (b)) 175 { 176 printf ("Error for (0+)^1\n"); 177 exit (1); 178 } 179 MPFR_SET_ZERO (a); 180 MPFR_SET_NEG (a); 181 mpfr_set_ui (b, 1, MPFR_RNDN); 182 res = mpfr_pow_ui (b, a, 5, MPFR_RNDN); 183 if (res != 0 || MPFR_IS_POS (b)) 184 { 185 printf ("Error for (0-)^5\n"); 186 exit (1); 187 } 188 MPFR_SET_ZERO (a); 189 MPFR_SET_NEG (a); 190 mpfr_set_si (b, -1, MPFR_RNDN); 191 res = mpfr_pow_ui (b, a, 6, MPFR_RNDN); 192 if (res != 0 || MPFR_IS_NEG (b)) 193 { 194 printf ("Error for (0-)^6\n"); 195 exit (1); 196 } 197 198 mpfr_set_prec (a, 122); 199 mpfr_set_prec (b, 122); 200 mpfr_set_str_binary (a, "0.10000010010000111101001110100101101010011110011100001111000001001101000110011001001001001011001011010110110110101000111011E1"); 201 mpfr_set_str_binary (b, "0.11111111100101001001000001000001100011100000001110111111100011111000111011100111111111110100011000111011000100100011001011E51290375"); 202 mpfr_pow_ui (a, a, 2026876995UL, MPFR_RNDU); 203 if (mpfr_cmp (a, b) != 0) 204 { 205 printf ("Error for x^2026876995\n"); 206 exit (1); 207 } 208 209 mpfr_set_prec (a, 29); 210 mpfr_set_prec (b, 29); 211 mpfr_set_str_binary (a, "1.0000000000000000000000001111"); 212 mpfr_set_str_binary (b, "1.1001101111001100111001010111e165"); 213 mpfr_pow_ui (a, a, 2055225053, MPFR_RNDZ); 214 if (mpfr_cmp (a, b) != 0) 215 { 216 printf ("Error for x^2055225053\n"); 217 printf ("Expected "); 218 mpfr_out_str (stdout, 2, 0, b, MPFR_RNDN); 219 printf ("\nGot "); 220 mpfr_out_str (stdout, 2, 0, a, MPFR_RNDN); 221 printf ("\n"); 222 exit (1); 223 } 224 225 /* worst case found by Vincent Lefevre, 25 Nov 2006 */ 226 mpfr_set_prec (a, 53); 227 mpfr_set_prec (b, 53); 228 mpfr_set_str_binary (a, "1.0000010110000100001000101101101001011101101011010111"); 229 mpfr_set_str_binary (b, "1.0000110111101111011010110100001100010000001010110100E1"); 230 mpfr_pow_ui (a, a, 35, MPFR_RNDN); 231 if (mpfr_cmp (a, b) != 0) 232 { 233 printf ("Error in mpfr_pow_ui for worst case (1)\n"); 234 printf ("Expected "); 235 mpfr_out_str (stdout, 2, 0, b, MPFR_RNDN); 236 printf ("\nGot "); 237 mpfr_out_str (stdout, 2, 0, a, MPFR_RNDN); 238 printf ("\n"); 239 exit (1); 240 } 241 /* worst cases found on 2006-11-26 */ 242 mpfr_set_str_binary (a, "1.0110100111010001101001010111001110010100111111000011"); 243 mpfr_set_str_binary (b, "1.1111010011101110001111010110000101110000110110101100E17"); 244 mpfr_pow_ui (a, a, 36, MPFR_RNDD); 245 if (mpfr_cmp (a, b) != 0) 246 { 247 printf ("Error in mpfr_pow_ui for worst case (2)\n"); 248 printf ("Expected "); 249 mpfr_out_str (stdout, 2, 0, b, MPFR_RNDN); 250 printf ("\nGot "); 251 mpfr_out_str (stdout, 2, 0, a, MPFR_RNDN); 252 printf ("\n"); 253 exit (1); 254 } 255 mpfr_set_str_binary (a, "1.1001010100001110000110111111100011011101110011000100"); 256 mpfr_set_str_binary (b, "1.1100011101101101100010110001000001110001111110010001E23"); 257 mpfr_pow_ui (a, a, 36, MPFR_RNDU); 258 if (mpfr_cmp (a, b) != 0) 259 { 260 printf ("Error in mpfr_pow_ui for worst case (3)\n"); 261 printf ("Expected "); 262 mpfr_out_str (stdout, 2, 0, b, MPFR_RNDN); 263 printf ("\nGot "); 264 mpfr_out_str (stdout, 2, 0, a, MPFR_RNDN); 265 printf ("\n"); 266 exit (1); 267 } 268 269 mpfr_clear (a); 270 mpfr_clear (b); 271 } 272 273 static void 274 check_pow_si (void) 275 { 276 mpfr_t x; 277 278 mpfr_init (x); 279 280 mpfr_set_nan (x); 281 mpfr_pow_si (x, x, -1, MPFR_RNDN); 282 MPFR_ASSERTN(mpfr_nan_p (x)); 283 284 mpfr_set_inf (x, 1); 285 mpfr_pow_si (x, x, -1, MPFR_RNDN); 286 MPFR_ASSERTN(mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_POS(x)); 287 288 mpfr_set_inf (x, -1); 289 mpfr_pow_si (x, x, -1, MPFR_RNDN); 290 MPFR_ASSERTN(mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_NEG(x)); 291 292 mpfr_set_inf (x, -1); 293 mpfr_pow_si (x, x, -2, MPFR_RNDN); 294 MPFR_ASSERTN(mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_POS(x)); 295 296 mpfr_set_ui (x, 0, MPFR_RNDN); 297 mpfr_pow_si (x, x, -1, MPFR_RNDN); 298 MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) > 0); 299 300 mpfr_set_ui (x, 0, MPFR_RNDN); 301 mpfr_neg (x, x, MPFR_RNDN); 302 mpfr_pow_si (x, x, -1, MPFR_RNDN); 303 MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) < 0); 304 305 mpfr_set_ui (x, 0, MPFR_RNDN); 306 mpfr_neg (x, x, MPFR_RNDN); 307 mpfr_pow_si (x, x, -2, MPFR_RNDN); 308 MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) > 0); 309 310 mpfr_set_si (x, 2, MPFR_RNDN); 311 mpfr_pow_si (x, x, LONG_MAX, MPFR_RNDN); /* 2^LONG_MAX */ 312 if (LONG_MAX > mpfr_get_emax () - 1) /* LONG_MAX + 1 > emax */ 313 { 314 MPFR_ASSERTN (mpfr_inf_p (x)); 315 } 316 else 317 { 318 MPFR_ASSERTN (mpfr_cmp_si_2exp (x, 1, (mpfr_exp_t) LONG_MAX)); 319 } 320 321 mpfr_set_si (x, 2, MPFR_RNDN); 322 mpfr_pow_si (x, x, LONG_MIN, MPFR_RNDN); /* 2^LONG_MIN */ 323 if (LONG_MIN + 1 < mpfr_get_emin ()) 324 { 325 MPFR_ASSERTN (mpfr_zero_p (x)); 326 } 327 else 328 { 329 MPFR_ASSERTN (mpfr_cmp_si_2exp (x, 1, (mpfr_exp_t) LONG_MIN)); 330 } 331 332 mpfr_set_si (x, 2, MPFR_RNDN); 333 mpfr_pow_si (x, x, LONG_MIN + 1, MPFR_RNDN); /* 2^(LONG_MIN+1) */ 334 if (mpfr_nan_p (x)) 335 { 336 printf ("Error in pow_si(2, LONG_MIN+1): got NaN\n"); 337 exit (1); 338 } 339 if (LONG_MIN + 2 < mpfr_get_emin ()) 340 { 341 MPFR_ASSERTN (mpfr_zero_p (x)); 342 } 343 else 344 { 345 MPFR_ASSERTN (mpfr_cmp_si_2exp (x, 1, (mpfr_exp_t) (LONG_MIN + 1))); 346 } 347 348 mpfr_set_si_2exp (x, 1, -1, MPFR_RNDN); /* 0.5 */ 349 mpfr_pow_si (x, x, LONG_MIN, MPFR_RNDN); /* 2^(-LONG_MIN) */ 350 if (LONG_MIN < 1 - mpfr_get_emax ()) /* 1 - LONG_MIN > emax */ 351 { 352 MPFR_ASSERTN (mpfr_inf_p (x)); 353 } 354 else 355 { 356 MPFR_ASSERTN (mpfr_cmp_si_2exp (x, 2, (mpfr_exp_t) - (LONG_MIN + 1))); 357 } 358 359 mpfr_clear (x); 360 } 361 362 static void 363 check_special_pow_si (void) 364 { 365 mpfr_t a, b; 366 mpfr_exp_t emin; 367 368 mpfr_init (a); 369 mpfr_init (b); 370 mpfr_set_str (a, "2E100000000", 10, MPFR_RNDN); 371 mpfr_set_si (b, -10, MPFR_RNDN); 372 test_pow (b, a, b, MPFR_RNDN); 373 if (!MPFR_IS_ZERO(b)) 374 { 375 printf("Pow(2E10000000, -10) failed\n"); 376 mpfr_dump (a); 377 mpfr_dump (b); 378 exit(1); 379 } 380 381 emin = mpfr_get_emin (); 382 mpfr_set_emin (-10); 383 mpfr_set_si (a, -2, MPFR_RNDN); 384 mpfr_pow_si (b, a, -10000, MPFR_RNDN); 385 if (!MPFR_IS_ZERO (b)) 386 { 387 printf ("Pow_so (1, -10000) doesn't underflow if emin=-10.\n"); 388 mpfr_dump (a); 389 mpfr_dump (b); 390 exit (1); 391 } 392 mpfr_set_emin (emin); 393 mpfr_clear (a); 394 mpfr_clear (b); 395 } 396 397 static void 398 pow_si_long_min (void) 399 { 400 mpfr_t x, y, z; 401 int inex; 402 403 mpfr_inits2 (sizeof(long) * CHAR_BIT + 32, x, y, z, (mpfr_ptr) 0); 404 mpfr_set_si_2exp (x, 3, -1, MPFR_RNDN); /* 1.5 */ 405 406 inex = mpfr_set_si (y, LONG_MIN, MPFR_RNDN); 407 MPFR_ASSERTN (inex == 0); 408 mpfr_nextbelow (y); 409 mpfr_pow (y, x, y, MPFR_RNDD); 410 411 inex = mpfr_set_si (z, LONG_MIN, MPFR_RNDN); 412 MPFR_ASSERTN (inex == 0); 413 mpfr_nextabove (z); 414 mpfr_pow (z, x, z, MPFR_RNDU); 415 416 mpfr_pow_si (x, x, LONG_MIN, MPFR_RNDN); /* 1.5^LONG_MIN */ 417 if (mpfr_cmp (x, y) < 0 || mpfr_cmp (x, z) > 0) 418 { 419 printf ("Error in pow_si_long_min\n"); 420 exit (1); 421 } 422 423 mpfr_clears (x, y, z, (mpfr_ptr) 0); 424 } 425 426 static void 427 check_inexact (mpfr_prec_t p) 428 { 429 mpfr_t x, y, z, t; 430 unsigned long u; 431 mpfr_prec_t q; 432 int inexact, cmp; 433 int rnd; 434 435 mpfr_init2 (x, p); 436 mpfr_init (y); 437 mpfr_init (z); 438 mpfr_init (t); 439 mpfr_urandomb (x, RANDS); 440 u = randlimb () % 2; 441 for (q = MPFR_PREC_MIN; q <= p; q++) 442 RND_LOOP_NO_RNDF(rnd) 443 { 444 mpfr_set_prec (y, q); 445 mpfr_set_prec (z, q + 10); 446 mpfr_set_prec (t, q); 447 inexact = mpfr_pow_ui (y, x, u, (mpfr_rnd_t) rnd); 448 cmp = mpfr_pow_ui (z, x, u, (mpfr_rnd_t) rnd); 449 /* Note: that test makes no sense for RNDF, since according to the 450 reference manual, if the mpfr_can_round() call succeeds, one would 451 have to use RNDN in the mpfr_set() call below, which might give a 452 different value for t that the value y obtained above. */ 453 if (mpfr_can_round (z, q + 10, (mpfr_rnd_t) rnd, (mpfr_rnd_t) rnd, q)) 454 { 455 cmp = mpfr_set (t, z, (mpfr_rnd_t) rnd) || cmp; 456 if (mpfr_cmp (y, t)) 457 { 458 printf ("results differ for u=%lu rnd=%s\n", 459 u, mpfr_print_rnd_mode ((mpfr_rnd_t) rnd)); 460 printf ("x="); mpfr_dump (x); 461 printf ("y="); mpfr_dump (y); 462 printf ("t="); mpfr_dump (t); 463 printf ("z="); mpfr_dump (z); 464 exit (1); 465 } 466 if (((inexact == 0) && (cmp != 0)) || 467 ((inexact != 0) && (cmp == 0))) 468 { 469 printf ("Wrong inexact flag for p=%u, q=%u, rnd=%s\n", 470 (unsigned int) p, (unsigned int) q, 471 mpfr_print_rnd_mode ((mpfr_rnd_t) rnd)); 472 printf ("expected %d, got %d\n", cmp, inexact); 473 printf ("u=%lu x=", u); mpfr_dump (x); 474 printf ("y="); mpfr_dump (y); 475 exit (1); 476 } 477 } 478 } 479 480 /* check exact power */ 481 mpfr_set_prec (x, p); 482 mpfr_set_prec (y, p); 483 mpfr_set_prec (z, p); 484 mpfr_set_ui (x, 4, MPFR_RNDN); 485 mpfr_set_str (y, "0.5", 10, MPFR_RNDN); 486 test_pow (z, x, y, MPFR_RNDZ); 487 488 mpfr_clear (x); 489 mpfr_clear (y); 490 mpfr_clear (z); 491 mpfr_clear (t); 492 } 493 494 static void 495 special (void) 496 { 497 mpfr_t x, y, z, t; 498 mpfr_exp_t emin, emax; 499 int inex; 500 501 mpfr_init2 (x, 53); 502 mpfr_init2 (y, 53); 503 mpfr_init2 (z, 53); 504 mpfr_init2 (t, 2); 505 506 mpfr_set_ui (x, 2, MPFR_RNDN); 507 mpfr_pow_si (x, x, -2, MPFR_RNDN); 508 if (mpfr_cmp_ui_2exp (x, 1, -2)) 509 { 510 printf ("Error in pow_si(x,x,-2) for x=2\n"); 511 exit (1); 512 } 513 mpfr_set_ui (x, 2, MPFR_RNDN); 514 mpfr_set_si (y, -2, MPFR_RNDN); 515 test_pow (x, x, y, MPFR_RNDN); 516 if (mpfr_cmp_ui_2exp (x, 1, -2)) 517 { 518 printf ("Error in pow(x,x,y) for x=2, y=-2\n"); 519 exit (1); 520 } 521 522 mpfr_set_prec (x, 2); 523 mpfr_set_str_binary (x, "1.0e-1"); 524 mpfr_set_prec (y, 53); 525 mpfr_set_str_binary (y, "0.11010110011100101010110011001010100111000001000101110E-1"); 526 mpfr_set_prec (z, 2); 527 test_pow (z, x, y, MPFR_RNDZ); 528 mpfr_set_str_binary (x, "1.0e-1"); 529 if (mpfr_cmp (x, z)) 530 { 531 printf ("Error in mpfr_pow (1)\n"); 532 exit (1); 533 } 534 535 mpfr_set_prec (x, 64); 536 mpfr_set_prec (y, 64); 537 mpfr_set_prec (z, 64); 538 mpfr_set_prec (t, 64); 539 mpfr_set_str_binary (x, "0.111011000111100000111010000101010100110011010000011"); 540 mpfr_set_str_binary (y, "0.111110010100110000011101100011010111000010000100101"); 541 mpfr_set_str_binary (t, "0.1110110011110110001000110100100001001111010011111000010000011001"); 542 543 test_pow (z, x, y, MPFR_RNDN); 544 if (mpfr_cmp (z, t)) 545 { 546 printf ("Error in mpfr_pow for prec=64, rnd=MPFR_RNDN\n"); 547 exit (1); 548 } 549 550 mpfr_set_prec (x, 53); 551 mpfr_set_prec (y, 53); 552 mpfr_set_prec (z, 53); 553 mpfr_set_str (x, "5.68824667828621954868e-01", 10, MPFR_RNDN); 554 mpfr_set_str (y, "9.03327850535952658895e-01", 10, MPFR_RNDN); 555 test_pow (z, x, y, MPFR_RNDZ); 556 if (mpfr_cmp_str1 (z, "0.60071044650456473235")) 557 { 558 printf ("Error in mpfr_pow for prec=53, rnd=MPFR_RNDZ\n"); 559 exit (1); 560 } 561 562 mpfr_set_prec (t, 2); 563 mpfr_set_prec (x, 30); 564 mpfr_set_prec (y, 30); 565 mpfr_set_prec (z, 30); 566 mpfr_set_str (x, "1.00000000001010111110001111011e1", 2, MPFR_RNDN); 567 mpfr_set_str (t, "-0.5", 10, MPFR_RNDN); 568 test_pow (z, x, t, MPFR_RNDN); 569 mpfr_set_str (y, "1.01101001111010101110000101111e-1", 2, MPFR_RNDN); 570 if (mpfr_cmp (z, y)) 571 { 572 printf ("Error in mpfr_pow for prec=30, rnd=MPFR_RNDN\n"); 573 exit (1); 574 } 575 576 mpfr_set_prec (x, 21); 577 mpfr_set_prec (y, 21); 578 mpfr_set_prec (z, 21); 579 mpfr_set_str (x, "1.11111100100001100101", 2, MPFR_RNDN); 580 test_pow (z, x, t, MPFR_RNDZ); 581 mpfr_set_str (y, "1.01101011010001100000e-1", 2, MPFR_RNDN); 582 if (mpfr_cmp (z, y)) 583 { 584 printf ("Error in mpfr_pow for prec=21, rnd=MPFR_RNDZ\n"); 585 printf ("Expected "); 586 mpfr_out_str (stdout, 2, 0, y, MPFR_RNDN); 587 printf ("\nGot "); 588 mpfr_out_str (stdout, 2, 0, z, MPFR_RNDN); 589 printf ("\n"); 590 exit (1); 591 } 592 593 /* From http://www.terra.es/personal9/ismaeljc/hall.htm */ 594 mpfr_set_prec (x, 113); 595 mpfr_set_prec (y, 2); 596 mpfr_set_prec (z, 169); 597 mpfr_set_str1 (x, "6078673043126084065007902175846955"); 598 mpfr_set_ui_2exp (y, 3, -1, MPFR_RNDN); 599 test_pow (z, x, y, MPFR_RNDZ); 600 if (mpfr_cmp_str1 (z, "473928882491000966028828671876527456070714790264144")) 601 { 602 printf ("Error in mpfr_pow for 6078673043126084065007902175846955"); 603 printf ("^(3/2), MPFR_RNDZ\nExpected "); 604 printf ("4.73928882491000966028828671876527456070714790264144e50"); 605 printf ("\nGot "); 606 mpfr_out_str (stdout, 10, 0, z, MPFR_RNDN); 607 printf ("\n"); 608 exit (1); 609 } 610 test_pow (z, x, y, MPFR_RNDU); 611 if (mpfr_cmp_str1 (z, "473928882491000966028828671876527456070714790264145")) 612 { 613 printf ("Error in mpfr_pow for 6078673043126084065007902175846955"); 614 printf ("^(3/2), MPFR_RNDU\nExpected "); 615 printf ("4.73928882491000966028828671876527456070714790264145e50"); 616 printf ("\nGot "); 617 mpfr_out_str (stdout, 10, 0, z, MPFR_RNDN); 618 printf ("\n"); 619 exit (1); 620 } 621 622 mpfr_set_inf (x, 1); 623 mpfr_set_prec (y, 2); 624 mpfr_set_str_binary (y, "1E10"); 625 test_pow (z, x, y, MPFR_RNDN); 626 MPFR_ASSERTN(mpfr_inf_p (z) && MPFR_IS_POS(z)); 627 mpfr_set_inf (x, -1); 628 test_pow (z, x, y, MPFR_RNDN); 629 MPFR_ASSERTN(mpfr_inf_p (z) && MPFR_IS_POS(z)); 630 mpfr_set_prec (y, 10); 631 mpfr_set_str_binary (y, "1.000000001E9"); 632 test_pow (z, x, y, MPFR_RNDN); 633 MPFR_ASSERTN(mpfr_inf_p (z) && MPFR_IS_NEG(z)); 634 mpfr_set_str_binary (y, "1.000000001E8"); 635 test_pow (z, x, y, MPFR_RNDN); 636 MPFR_ASSERTN(mpfr_inf_p (z) && MPFR_IS_POS(z)); 637 638 mpfr_set_inf (x, -1); 639 mpfr_set_prec (y, 2 * mp_bits_per_limb); 640 mpfr_set_ui (y, 1, MPFR_RNDN); 641 mpfr_mul_2exp (y, y, mp_bits_per_limb - 1, MPFR_RNDN); 642 /* y = 2^(mp_bits_per_limb - 1) */ 643 test_pow (z, x, y, MPFR_RNDN); 644 MPFR_ASSERTN(mpfr_inf_p (z) && MPFR_IS_POS(z)); 645 mpfr_nextabove (y); 646 test_pow (z, x, y, MPFR_RNDN); 647 /* y = 2^(mp_bits_per_limb - 1) + epsilon */ 648 MPFR_ASSERTN(mpfr_inf_p (z) && MPFR_IS_POS(z)); 649 mpfr_nextbelow (y); 650 mpfr_div_2exp (y, y, 1, MPFR_RNDN); 651 mpfr_nextabove (y); 652 test_pow (z, x, y, MPFR_RNDN); 653 /* y = 2^(mp_bits_per_limb - 2) + epsilon */ 654 MPFR_ASSERTN(mpfr_inf_p (z) && MPFR_IS_POS(z)); 655 656 mpfr_set_si (x, -1, MPFR_RNDN); 657 mpfr_set_prec (y, 2); 658 mpfr_set_str_binary (y, "1E10"); 659 test_pow (z, x, y, MPFR_RNDN); 660 MPFR_ASSERTN(mpfr_cmp_ui (z, 1) == 0); 661 662 /* Check (-0)^(17.0001) */ 663 mpfr_set_prec (x, 6); 664 mpfr_set_prec (y, 640); 665 MPFR_SET_ZERO (x); MPFR_SET_NEG (x); 666 mpfr_set_ui (y, 17, MPFR_RNDN); mpfr_nextabove (y); 667 test_pow (z, x, y, MPFR_RNDN); 668 MPFR_ASSERTN (MPFR_IS_ZERO (z) && MPFR_IS_POS (z)); 669 670 /* Bugs reported by Kevin Rauch on 29 Oct 2007 */ 671 emin = mpfr_get_emin (); 672 emax = mpfr_get_emax (); 673 mpfr_set_emin (-1000000); 674 mpfr_set_emax ( 1000000); 675 mpfr_set_prec (x, 64); 676 mpfr_set_prec (y, 64); 677 mpfr_set_prec (z, 64); 678 mpfr_set_str (x, "-0.5", 10, MPFR_RNDN); 679 mpfr_set_str (y, "-0.ffffffffffffffff", 16, MPFR_RNDN); 680 mpfr_set_exp (y, mpfr_get_emax ()); 681 inex = mpfr_pow (z, x, y, MPFR_RNDN); 682 /* (-0.5)^(-n) = 1/2^n for n even */ 683 MPFR_ASSERTN(mpfr_inf_p (z) && MPFR_IS_POS (z) && inex > 0); 684 685 /* (-1)^(-n) = 1 for n even */ 686 mpfr_set_str (x, "-1", 10, MPFR_RNDN); 687 inex = mpfr_pow (z, x, y, MPFR_RNDN); 688 MPFR_ASSERTN(mpfr_cmp_ui (z, 1) == 0 && inex == 0); 689 690 /* (-1)^n = 1 for n even */ 691 mpfr_set_str (x, "-1", 10, MPFR_RNDN); 692 mpfr_neg (y, y, MPFR_RNDN); 693 inex = mpfr_pow (z, x, y, MPFR_RNDN); 694 MPFR_ASSERTN(mpfr_cmp_ui (z, 1) == 0 && inex == 0); 695 696 /* (-1.5)^n = +Inf for n even */ 697 mpfr_set_str (x, "-1.5", 10, MPFR_RNDN); 698 inex = mpfr_pow (z, x, y, MPFR_RNDN); 699 MPFR_ASSERTN(mpfr_inf_p (z) && MPFR_IS_POS (z) && inex > 0); 700 701 /* (-n)^1.5 = NaN for n even */ 702 mpfr_neg (y, y, MPFR_RNDN); 703 mpfr_set_str (x, "1.5", 10, MPFR_RNDN); 704 inex = mpfr_pow (z, y, x, MPFR_RNDN); 705 MPFR_ASSERTN(mpfr_nan_p (z)); 706 707 /* x^(-1.5) = NaN for x small < 0 */ 708 mpfr_set_str (x, "-0.8", 16, MPFR_RNDN); 709 mpfr_set_exp (x, mpfr_get_emin ()); 710 mpfr_set_str (y, "-1.5", 10, MPFR_RNDN); 711 inex = mpfr_pow (z, x, y, MPFR_RNDN); 712 MPFR_ASSERTN(mpfr_nan_p (z)); 713 714 mpfr_set_emin (emin); 715 mpfr_set_emax (emax); 716 mpfr_clear (x); 717 mpfr_clear (y); 718 mpfr_clear (z); 719 mpfr_clear (t); 720 } 721 722 static void 723 particular_cases (void) 724 { 725 mpfr_t t[11], r, r2; 726 mpz_t z; 727 long si; 728 729 static const char *name[11] = { 730 "NaN", "+inf", "-inf", "+0", "-0", "+1", "-1", "+2", "-2", "+0.5", "-0.5"}; 731 int i, j; 732 int error = 0; 733 734 mpz_init (z); 735 736 for (i = 0; i < 11; i++) 737 mpfr_init2 (t[i], 2); 738 mpfr_init2 (r, 6); 739 mpfr_init2 (r2, 6); 740 741 mpfr_set_nan (t[0]); 742 mpfr_set_inf (t[1], 1); 743 mpfr_set_ui (t[3], 0, MPFR_RNDN); 744 mpfr_set_ui (t[5], 1, MPFR_RNDN); 745 mpfr_set_ui (t[7], 2, MPFR_RNDN); 746 mpfr_div_2ui (t[9], t[5], 1, MPFR_RNDN); 747 for (i = 1; i < 11; i += 2) 748 mpfr_neg (t[i+1], t[i], MPFR_RNDN); 749 750 for (i = 0; i < 11; i++) 751 for (j = 0; j < 11; j++) 752 { 753 double d; 754 int p; 755 static const int q[11][11] = { 756 /* NaN +inf -inf +0 -0 +1 -1 +2 -2 +0.5 -0.5 */ 757 /* NaN */ { 0, 0, 0, 128, 128, 0, 0, 0, 0, 0, 0 }, 758 /* +inf */ { 0, 1, 2, 128, 128, 1, 2, 1, 2, 1, 2 }, 759 /* -inf */ { 0, 1, 2, 128, 128, -1, -2, 1, 2, 1, 2 }, 760 /* +0 */ { 0, 2, 1, 128, 128, 2, 1, 2, 1, 2, 1 }, 761 /* -0 */ { 0, 2, 1, 128, 128, -2, -1, 2, 1, 2, 1 }, 762 /* +1 */ {128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 }, 763 /* -1 */ { 0, 128, 128, 128, 128,-128,-128, 128, 128, 0, 0 }, 764 /* +2 */ { 0, 1, 2, 128, 128, 256, 64, 512, 32, 180, 90 }, 765 /* -2 */ { 0, 1, 2, 128, 128,-256, -64, 512, 32, 0, 0 }, 766 /* +0.5 */ { 0, 2, 1, 128, 128, 64, 256, 32, 512, 90, 180 }, 767 /* -0.5 */ { 0, 2, 1, 128, 128, -64,-256, 32, 512, 0, 0 } 768 }; 769 /* This define is used to make the following table readable */ 770 #define N MPFR_FLAGS_NAN 771 #define I MPFR_FLAGS_INEXACT 772 #define D MPFR_FLAGS_DIVBY0 773 static const unsigned int f[11][11] = { 774 /* NaN +inf -inf +0 -0 +1 -1 +2 -2 +0.5 -0.5 */ 775 /* NaN */ { N, N, N, 0, 0, N, N, N, N, N, N }, 776 /* +inf */ { N, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 777 /* -inf */ { N, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 778 /* +0 */ { N, 0, 0, 0, 0, 0, D, 0, D, 0, D }, 779 /* -0 */ { N, 0, 0, 0, 0, 0, D, 0, D, 0, D }, 780 /* +1 */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 781 /* -1 */ { N, 0, 0, 0, 0, 0, 0, 0, 0, N, N }, 782 /* +2 */ { N, 0, 0, 0, 0, 0, 0, 0, 0, I, I }, 783 /* -2 */ { N, 0, 0, 0, 0, 0, 0, 0, 0, N, N }, 784 /* +0.5 */ { N, 0, 0, 0, 0, 0, 0, 0, 0, I, I }, 785 /* -0.5 */ { N, 0, 0, 0, 0, 0, 0, 0, 0, N, N } 786 }; 787 #undef N 788 #undef I 789 #undef D 790 mpfr_clear_flags (); 791 test_pow (r, t[i], t[j], MPFR_RNDN); 792 p = mpfr_nan_p (r) ? 0 : mpfr_inf_p (r) ? 1 : 793 mpfr_cmp_ui (r, 0) == 0 ? 2 : 794 (d = mpfr_get_d (r, MPFR_RNDN), (int) (ABS(d) * 128.0)); 795 if (p != 0 && MPFR_IS_NEG (r)) 796 p = -p; 797 if (p != q[i][j]) 798 { 799 printf ("Error in mpfr_pow for (%s)^(%s) (%d,%d):\n" 800 "got %d instead of %d\n", 801 name[i], name[j], i, j, p, q[i][j]); 802 mpfr_dump (r); 803 error = 1; 804 } 805 if (__gmpfr_flags != f[i][j]) 806 { 807 printf ("Error in mpfr_pow for (%s)^(%s) (%d,%d):\n" 808 "Flags = %u instead of expected %u\n", 809 name[i], name[j], i, j, 810 (unsigned int) __gmpfr_flags, f[i][j]); 811 mpfr_dump (r); 812 error = 1; 813 } 814 /* Perform the same tests with pow_z & pow_si & pow_ui 815 if t[j] is an integer */ 816 if (mpfr_integer_p (t[j])) 817 { 818 /* mpfr_pow_z */ 819 mpfr_clear_flags (); 820 mpfr_get_z (z, t[j], MPFR_RNDN); 821 mpfr_pow_z (r, t[i], z, MPFR_RNDN); 822 p = mpfr_nan_p (r) ? 0 : mpfr_inf_p (r) ? 1 : 823 mpfr_cmp_ui (r, 0) == 0 ? 2 : 824 (d = mpfr_get_d (r, MPFR_RNDN), (int) (ABS(d) * 128.0)); 825 if (p != 0 && MPFR_IS_NEG (r)) 826 p = -p; 827 if (p != q[i][j]) 828 { 829 printf ("Error in mpfr_pow_z for (%s)^(%s) (%d,%d):\n" 830 "got %d instead of %d\n", 831 name[i], name[j], i, j, p, q[i][j]); 832 mpfr_dump (r); 833 error = 1; 834 } 835 if (__gmpfr_flags != f[i][j]) 836 { 837 printf ("Error in mpfr_pow_z for (%s)^(%s) (%d,%d):\n" 838 "Flags = %u instead of expected %u\n", 839 name[i], name[j], i, j, 840 (unsigned int) __gmpfr_flags, f[i][j]); 841 mpfr_dump (r); 842 error = 1; 843 } 844 /* mpfr_pow_si */ 845 mpfr_clear_flags (); 846 si = mpfr_get_si (t[j], MPFR_RNDN); 847 mpfr_pow_si (r, t[i], si, MPFR_RNDN); 848 p = mpfr_nan_p (r) ? 0 : mpfr_inf_p (r) ? 1 : 849 mpfr_cmp_ui (r, 0) == 0 ? 2 : 850 (d = mpfr_get_d (r, MPFR_RNDN), (int) (ABS(d) * 128.0)); 851 if (p != 0 && MPFR_IS_NEG (r)) 852 p = -p; 853 if (p != q[i][j]) 854 { 855 printf ("Error in mpfr_pow_si for (%s)^(%s) (%d,%d):\n" 856 "got %d instead of %d\n", 857 name[i], name[j], i, j, p, q[i][j]); 858 mpfr_dump (r); 859 error = 1; 860 } 861 if (__gmpfr_flags != f[i][j]) 862 { 863 printf ("Error in mpfr_pow_si for (%s)^(%s) (%d,%d):\n" 864 "Flags = %u instead of expected %u\n", 865 name[i], name[j], i, j, 866 (unsigned int) __gmpfr_flags, f[i][j]); 867 mpfr_dump (r); 868 error = 1; 869 } 870 /* if si >= 0, test mpfr_pow_ui */ 871 if (si >= 0) 872 { 873 mpfr_clear_flags (); 874 mpfr_pow_ui (r, t[i], si, MPFR_RNDN); 875 p = mpfr_nan_p (r) ? 0 : mpfr_inf_p (r) ? 1 : 876 mpfr_cmp_ui (r, 0) == 0 ? 2 : 877 (d = mpfr_get_d (r, MPFR_RNDN), (int) (ABS(d) * 128.0)); 878 if (p != 0 && MPFR_IS_NEG (r)) 879 p = -p; 880 if (p != q[i][j]) 881 { 882 printf ("Error in mpfr_pow_ui for (%s)^(%s) (%d,%d):\n" 883 "got %d instead of %d\n", 884 name[i], name[j], i, j, p, q[i][j]); 885 mpfr_dump (r); 886 error = 1; 887 } 888 if (__gmpfr_flags != f[i][j]) 889 { 890 printf ("Error in mpfr_pow_ui for (%s)^(%s) (%d,%d):\n" 891 "Flags = %u instead of expected %u\n", 892 name[i], name[j], i, j, 893 (unsigned int) __gmpfr_flags, f[i][j]); 894 mpfr_dump (r); 895 error = 1; 896 } 897 } 898 } /* integer_p */ 899 /* Perform the same tests with mpfr_ui_pow */ 900 if (mpfr_integer_p (t[i]) && MPFR_IS_POS (t[i])) 901 { 902 /* mpfr_ui_pow */ 903 mpfr_clear_flags (); 904 si = mpfr_get_si (t[i], MPFR_RNDN); 905 mpfr_ui_pow (r, si, t[j], MPFR_RNDN); 906 p = mpfr_nan_p (r) ? 0 : mpfr_inf_p (r) ? 1 : 907 mpfr_cmp_ui (r, 0) == 0 ? 2 : 908 (d = mpfr_get_d (r, MPFR_RNDN), (int) (ABS(d) * 128.0)); 909 if (p != 0 && MPFR_IS_NEG (r)) 910 p = -p; 911 if (p != q[i][j]) 912 { 913 printf ("Error in mpfr_ui_pow for (%s)^(%s) (%d,%d):\n" 914 "got %d instead of %d\n", 915 name[i], name[j], i, j, p, q[i][j]); 916 mpfr_dump (r); 917 error = 1; 918 } 919 if (__gmpfr_flags != f[i][j]) 920 { 921 printf ("Error in mpfr_ui_pow for (%s)^(%s) (%d,%d):\n" 922 "Flags = %u instead of expected %u\n", 923 name[i], name[j], i, j, 924 (unsigned int) __gmpfr_flags, f[i][j]); 925 mpfr_dump (r); 926 error = 1; 927 } 928 } 929 } 930 931 for (i = 0; i < 11; i++) 932 mpfr_clear (t[i]); 933 mpfr_clear (r); 934 mpfr_clear (r2); 935 mpz_clear (z); 936 937 if (error) 938 exit (1); 939 } 940 941 static void 942 underflows (void) 943 { 944 mpfr_t x, y, z; 945 int err = 0; 946 int inexact; 947 int i; 948 mpfr_exp_t emin; 949 950 mpfr_init2 (x, 64); 951 mpfr_init2 (y, 64); 952 953 mpfr_set_ui (x, 1, MPFR_RNDN); 954 mpfr_set_exp (x, mpfr_get_emin()); 955 956 for (i = 3; i < 10; i++) 957 { 958 mpfr_set_ui (y, i, MPFR_RNDN); 959 mpfr_div_2ui (y, y, 1, MPFR_RNDN); 960 test_pow (y, x, y, MPFR_RNDN); 961 if (!MPFR_IS_FP(y) || mpfr_cmp_ui (y, 0)) 962 { 963 printf ("Error in mpfr_pow for "); 964 mpfr_out_str (stdout, 2, 0, x, MPFR_RNDN); 965 printf (" ^ (%d/2)\nGot ", i); 966 mpfr_out_str (stdout, 2, 0, y, MPFR_RNDN); 967 printf (" instead of 0.\n"); 968 exit (1); 969 } 970 } 971 972 mpfr_init2 (z, 55); 973 mpfr_set_str (x, "0.110011010011101001110001110100010000110111101E0", 974 2, MPFR_RNDN); 975 mpfr_set_str (y, "0.101110010011111001011010100011011100111110011E40", 976 2, MPFR_RNDN); 977 mpfr_clear_flags (); 978 inexact = mpfr_pow (z, x, y, MPFR_RNDU); 979 if (!mpfr_underflow_p ()) 980 { 981 printf ("Underflow flag is not set for special underflow test.\n"); 982 err = 1; 983 } 984 if (inexact <= 0) 985 { 986 printf ("Ternary value is wrong for special underflow test.\n"); 987 err = 1; 988 } 989 mpfr_set_ui (x, 0, MPFR_RNDN); 990 mpfr_nextabove (x); 991 if (mpfr_cmp (x, z) != 0) 992 { 993 printf ("Wrong value for special underflow test.\nGot "); 994 mpfr_out_str (stdout, 2, 0, z, MPFR_RNDN); 995 printf ("\ninstead of "); 996 mpfr_out_str (stdout, 2, 2, x, MPFR_RNDN); 997 printf ("\n"); 998 err = 1; 999 } 1000 if (err) 1001 exit (1); 1002 1003 /* MPFR currently (2006-08-19) segfaults on the following code (and 1004 possibly makes other programs crash due to the lack of memory), 1005 because y is converted into an mpz_t, and the required precision 1006 is too high. */ 1007 mpfr_set_prec (x, 2); 1008 mpfr_set_prec (y, 2); 1009 mpfr_set_prec (z, 12); 1010 mpfr_set_ui_2exp (x, 3, -2, MPFR_RNDN); 1011 mpfr_set_ui_2exp (y, 1, mpfr_get_emax () - 1, MPFR_RNDN); 1012 mpfr_clear_flags (); 1013 mpfr_pow (z, x, y, MPFR_RNDN); 1014 if (!mpfr_underflow_p () || MPFR_NOTZERO (z)) 1015 { 1016 printf ("Underflow test with large y fails.\n"); 1017 exit (1); 1018 } 1019 1020 emin = mpfr_get_emin (); 1021 mpfr_set_emin (-256); 1022 mpfr_set_prec (x, 2); 1023 mpfr_set_prec (y, 2); 1024 mpfr_set_prec (z, 12); 1025 mpfr_set_ui_2exp (x, 3, -2, MPFR_RNDN); 1026 mpfr_set_ui_2exp (y, 1, 38, MPFR_RNDN); 1027 mpfr_clear_flags (); 1028 inexact = mpfr_pow (z, x, y, MPFR_RNDN); 1029 if (!mpfr_underflow_p () || MPFR_NOTZERO (z) || inexact >= 0) 1030 { 1031 printf ("Bad underflow detection for 0.75^(2^38). Obtained:\n" 1032 "Underflow flag... %-3s (should be 'yes')\n" 1033 "Zero result...... %-3s (should be 'yes')\n" 1034 "Inexact value.... %-3d (should be negative)\n", 1035 mpfr_underflow_p () ? "yes" : "no", 1036 MPFR_IS_ZERO (z) ? "yes" : "no", inexact); 1037 exit (1); 1038 } 1039 mpfr_set_emin (emin); 1040 1041 emin = mpfr_get_emin (); 1042 mpfr_set_emin (-256); 1043 mpfr_set_prec (x, 2); 1044 mpfr_set_prec (y, 40); 1045 mpfr_set_prec (z, 12); 1046 mpfr_set_ui_2exp (x, 3, -1, MPFR_RNDN); 1047 mpfr_set_si_2exp (y, -1, 38, MPFR_RNDN); 1048 for (i = 0; i < 4; i++) 1049 { 1050 if (i == 2) 1051 mpfr_neg (x, x, MPFR_RNDN); 1052 mpfr_clear_flags (); 1053 inexact = mpfr_pow (z, x, y, MPFR_RNDN); 1054 if (!mpfr_underflow_p () || MPFR_NOTZERO (z) || 1055 (i == 3 ? (inexact <= 0) : (inexact >= 0))) 1056 { 1057 printf ("Bad underflow detection for ("); 1058 mpfr_out_str (stdout, 10, 0, x, MPFR_RNDN); 1059 printf (")^(-2^38-%d). Obtained:\n" 1060 "Overflow flag.... %-3s (should be 'no')\n" 1061 "Underflow flag... %-3s (should be 'yes')\n" 1062 "Zero result...... %-3s (should be 'yes')\n" 1063 "Inexact value.... %-3d (should be %s)\n", i, 1064 mpfr_overflow_p () ? "yes" : "no", 1065 mpfr_underflow_p () ? "yes" : "no", 1066 MPFR_IS_ZERO (z) ? "yes" : "no", inexact, 1067 i == 3 ? "positive" : "negative"); 1068 exit (1); 1069 } 1070 inexact = mpfr_sub_ui (y, y, 1, MPFR_RNDN); 1071 MPFR_ASSERTN (inexact == 0); 1072 } 1073 mpfr_set_emin (emin); 1074 1075 mpfr_clears (x, y, z, (mpfr_ptr) 0); 1076 } 1077 1078 static void 1079 overflows (void) 1080 { 1081 mpfr_t a, b; 1082 1083 /* bug found by Ming J. Tsai <mingjt@delvron.us>, 4 Oct 2003 */ 1084 1085 mpfr_init_set_str (a, "5.1e32", 10, MPFR_RNDN); 1086 mpfr_init (b); 1087 1088 test_pow (b, a, a, MPFR_RNDN); 1089 if (!(mpfr_inf_p (b) && mpfr_sgn (b) > 0)) 1090 { 1091 printf ("Error for a^a for a=5.1e32\n"); 1092 printf ("Expected +Inf, got "); 1093 mpfr_out_str (stdout, 10, 0, b, MPFR_RNDN); 1094 printf ("\n"); 1095 exit (1); 1096 } 1097 1098 mpfr_clear(a); 1099 mpfr_clear(b); 1100 } 1101 1102 static void 1103 overflows2 (void) 1104 { 1105 mpfr_t x, y, z; 1106 mpfr_exp_t emin, emax; 1107 int e; 1108 1109 /* x^y in reduced exponent range, where x = 2^b and y is not an integer 1110 (so that mpfr_pow_z is not used). */ 1111 1112 emin = mpfr_get_emin (); 1113 emax = mpfr_get_emax (); 1114 set_emin (-128); 1115 1116 mpfr_inits2 (16, x, y, z, (mpfr_ptr) 0); 1117 1118 mpfr_set_si_2exp (x, 1, -64, MPFR_RNDN); /* 2^(-64) */ 1119 mpfr_set_si_2exp (y, -1, -1, MPFR_RNDN); /* -0.5 */ 1120 for (e = 2; e <= 32; e += 17) 1121 { 1122 set_emax (e); 1123 mpfr_clear_flags (); 1124 mpfr_pow (z, x, y, MPFR_RNDN); 1125 if (MPFR_IS_NEG (z) || ! mpfr_inf_p (z)) 1126 { 1127 printf ("Error in overflows2 (e = %d): expected +Inf, got ", e); 1128 mpfr_dump (z); 1129 exit (1); 1130 } 1131 if (__gmpfr_flags != (MPFR_FLAGS_OVERFLOW | MPFR_FLAGS_INEXACT)) 1132 { 1133 printf ("Error in overflows2 (e = %d): bad flags (%u)\n", 1134 e, (unsigned int) __gmpfr_flags); 1135 exit (1); 1136 } 1137 } 1138 1139 mpfr_clears (x, y, z, (mpfr_ptr) 0); 1140 1141 set_emin (emin); 1142 set_emax (emax); 1143 } 1144 1145 static void 1146 overflows3 (void) 1147 { 1148 /* x^y where x = 2^b, y is not an integer (so that mpfr_pow_z is not used) 1149 and b * y = emax in the extended exponent range. If emax is divisible 1150 by 3, we choose x = 2^(-2*emax/3) and y = -3/2. 1151 Test also with nextbelow(x). */ 1152 1153 if (MPFR_EMAX_MAX % 3 == 0) 1154 { 1155 mpfr_t x, y, z, t; 1156 mpfr_exp_t emin, emax; 1157 unsigned int flags; 1158 int i; 1159 1160 emin = mpfr_get_emin (); 1161 emax = mpfr_get_emax (); 1162 set_emin (MPFR_EMIN_MIN); 1163 set_emax (MPFR_EMAX_MAX); 1164 1165 mpfr_inits2 (16, x, y, z, t, (mpfr_ptr) 0); 1166 1167 mpfr_set_si_2exp (x, 1, -2 * (MPFR_EMAX_MAX / 3), MPFR_RNDN); 1168 for (i = 0; i <= 1; i++) 1169 { 1170 mpfr_set_si_2exp (y, -3, -1, MPFR_RNDN); 1171 mpfr_clear_flags (); 1172 mpfr_pow (z, x, y, MPFR_RNDN); 1173 if (MPFR_IS_NEG (z) || ! mpfr_inf_p (z)) 1174 { 1175 printf ("Error in overflows3 (RNDN, i = %d): expected +Inf," 1176 " got ", i); 1177 mpfr_dump (z); 1178 exit (1); 1179 } 1180 if (__gmpfr_flags != (MPFR_FLAGS_OVERFLOW | MPFR_FLAGS_INEXACT)) 1181 { 1182 printf ("Error in overflows3 (RNDN, i = %d): bad flags (%u)\n", 1183 i, (unsigned int) __gmpfr_flags); 1184 exit (1); 1185 } 1186 1187 mpfr_clear_flags (); 1188 mpfr_pow (z, x, y, MPFR_RNDZ); 1189 flags = __gmpfr_flags; 1190 mpfr_set (t, z, MPFR_RNDN); 1191 mpfr_nextabove (t); 1192 if (MPFR_IS_NEG (z) || mpfr_inf_p (z) || ! mpfr_inf_p (t)) 1193 { 1194 printf ("Error in overflows3 (RNDZ, i = %d):\nexpected ", i); 1195 mpfr_set_inf (t, 1); 1196 mpfr_nextbelow (t); 1197 mpfr_dump (t); 1198 printf ("got "); 1199 mpfr_dump (z); 1200 exit (1); 1201 } 1202 if (flags != (MPFR_FLAGS_OVERFLOW | MPFR_FLAGS_INEXACT)) 1203 { 1204 printf ("Error in overflows3 (RNDZ, i = %d): bad flags (%u)\n", 1205 i, flags); 1206 exit (1); 1207 } 1208 mpfr_nextbelow (x); 1209 } 1210 1211 mpfr_clears (x, y, z, t, (mpfr_ptr) 0); 1212 1213 set_emin (emin); 1214 set_emax (emax); 1215 } 1216 } 1217 1218 static void 1219 x_near_one (void) 1220 { 1221 mpfr_t x, y, z; 1222 int inex; 1223 1224 mpfr_init2 (x, 32); 1225 mpfr_init2 (y, 4); 1226 mpfr_init2 (z, 33); 1227 1228 mpfr_set_ui (x, 1, MPFR_RNDN); 1229 mpfr_nextbelow (x); 1230 mpfr_set_ui_2exp (y, 11, -2, MPFR_RNDN); 1231 inex = mpfr_pow (z, x, y, MPFR_RNDN); 1232 if (mpfr_cmp_str (z, "0.111111111111111111111111111111011E0", 2, MPFR_RNDN) 1233 || inex <= 0) 1234 { 1235 printf ("Failure in x_near_one, got inex = %d and\nz = ", inex); 1236 mpfr_dump (z); 1237 } 1238 1239 mpfr_clears (x, y, z, (mpfr_ptr) 0); 1240 } 1241 1242 static int 1243 mpfr_pow275 (mpfr_ptr y, mpfr_srcptr x, mpfr_rnd_t r) 1244 { 1245 mpfr_t z; 1246 int inex; 1247 1248 mpfr_init2 (z, 4); 1249 mpfr_set_ui_2exp (z, 11, -2, MPFR_RNDN); 1250 inex = mpfr_pow (y, x, z, MPFR_RNDN); 1251 mpfr_clear (z); 1252 return inex; 1253 } 1254 1255 /* Bug found by Kevin P. Rauch */ 1256 static void 1257 bug20071103 (void) 1258 { 1259 mpfr_t x, y, z; 1260 mpfr_exp_t emin, emax; 1261 1262 emin = mpfr_get_emin (); 1263 emax = mpfr_get_emax (); 1264 mpfr_set_emin (-1000000); 1265 mpfr_set_emax ( 1000000); 1266 1267 mpfr_inits2 (64, x, y, z, (mpfr_ptr) 0); 1268 mpfr_set_si_2exp (x, -3, -1, MPFR_RNDN); /* x = -1.5 */ 1269 mpfr_set_str (y, "-0.ffffffffffffffff", 16, MPFR_RNDN); 1270 mpfr_set_exp (y, mpfr_get_emax ()); 1271 mpfr_clear_flags (); 1272 mpfr_pow (z, x, y, MPFR_RNDN); 1273 MPFR_ASSERTN (mpfr_zero_p (z) && MPFR_IS_POS (z) && 1274 __gmpfr_flags == (MPFR_FLAGS_UNDERFLOW | MPFR_FLAGS_INEXACT)); 1275 mpfr_clears (x, y, z, (mpfr_ptr) 0); 1276 1277 set_emin (emin); 1278 set_emax (emax); 1279 } 1280 1281 /* Bug found by Kevin P. Rauch */ 1282 static void 1283 bug20071104 (void) 1284 { 1285 mpfr_t x, y, z; 1286 mpfr_exp_t emin, emax; 1287 int inex; 1288 1289 emin = mpfr_get_emin (); 1290 emax = mpfr_get_emax (); 1291 mpfr_set_emin (-1000000); 1292 mpfr_set_emax ( 1000000); 1293 1294 mpfr_inits2 (20, x, y, z, (mpfr_ptr) 0); 1295 mpfr_set_ui (x, 0, MPFR_RNDN); 1296 mpfr_nextbelow (x); /* x = -2^(emin-1) */ 1297 mpfr_set_si (y, -2, MPFR_RNDN); /* y = -2 */ 1298 mpfr_clear_flags (); 1299 inex = mpfr_pow (z, x, y, MPFR_RNDN); 1300 if (! mpfr_inf_p (z) || MPFR_IS_NEG (z)) 1301 { 1302 printf ("Error in bug20071104: expected +Inf, got "); 1303 mpfr_dump (z); 1304 exit (1); 1305 } 1306 if (inex <= 0) 1307 { 1308 printf ("Error in bug20071104: bad ternary value (%d)\n", inex); 1309 exit (1); 1310 } 1311 if (__gmpfr_flags != (MPFR_FLAGS_OVERFLOW | MPFR_FLAGS_INEXACT)) 1312 { 1313 printf ("Error in bug20071104: bad flags (%u)\n", 1314 (unsigned int) __gmpfr_flags); 1315 exit (1); 1316 } 1317 mpfr_clears (x, y, z, (mpfr_ptr) 0); 1318 1319 set_emin (emin); 1320 set_emax (emax); 1321 } 1322 1323 /* Bug found by Kevin P. Rauch */ 1324 static void 1325 bug20071127 (void) 1326 { 1327 mpfr_t x, y, z; 1328 int i, tern; 1329 mpfr_exp_t emin, emax; 1330 1331 emin = mpfr_get_emin (); 1332 emax = mpfr_get_emax (); 1333 mpfr_set_emin (-1000000); 1334 mpfr_set_emax ( 1000000); 1335 1336 mpfr_init2 (x, 128); 1337 mpfr_init2 (y, 128); 1338 mpfr_init2 (z, 128); 1339 1340 mpfr_set_str (x, "0.80000000000000000000000000000001", 16, MPFR_RNDN); 1341 1342 for (i = 1; i < 9; i *= 2) 1343 { 1344 mpfr_set_str (y, "8000000000000000", 16, MPFR_RNDN); 1345 mpfr_add_si (y, y, i, MPFR_RNDN); 1346 tern = mpfr_pow (z, x, y, MPFR_RNDN); 1347 MPFR_ASSERTN (mpfr_zero_p (z) && MPFR_IS_POS (z) && tern < 0); 1348 } 1349 1350 mpfr_clear (x); 1351 mpfr_clear (y); 1352 mpfr_clear (z); 1353 1354 mpfr_set_emin (emin); 1355 mpfr_set_emax (emax); 1356 } 1357 1358 /* Bug found by Kevin P. Rauch */ 1359 static void 1360 bug20071128 (void) 1361 { 1362 mpfr_t max_val, x, y, z; 1363 int i, tern; 1364 mpfr_exp_t emin, emax; 1365 1366 emin = mpfr_get_emin (); 1367 emax = mpfr_get_emax (); 1368 mpfr_set_emin (-1000000); 1369 mpfr_set_emax ( 1000000); 1370 1371 mpfr_init2 (max_val, 64); 1372 mpfr_init2 (x, 64); 1373 mpfr_init2 (y, 64); 1374 mpfr_init2 (z, 64); 1375 1376 mpfr_set_str (max_val, "0.ffffffffffffffff", 16, MPFR_RNDN); 1377 mpfr_set_exp (max_val, mpfr_get_emax ()); 1378 1379 mpfr_neg (x, max_val, MPFR_RNDN); 1380 1381 /* on 64-bit machines */ 1382 for (i = 41; i < 45; i++) 1383 { 1384 mpfr_set_si_2exp (y, -1, i, MPFR_RNDN); 1385 mpfr_add_si (y, y, 1, MPFR_RNDN); 1386 tern = mpfr_pow (z, x, y, MPFR_RNDN); 1387 MPFR_ASSERTN (mpfr_zero_p (z) && MPFR_IS_NEG (z) && tern > 0); 1388 } 1389 1390 /* on 32-bit machines */ 1391 for (i = 9; i < 13; i++) 1392 { 1393 mpfr_set_si_2exp (y, -1, i, MPFR_RNDN); 1394 mpfr_add_si (y, y, 1, MPFR_RNDN); 1395 tern = mpfr_pow (z, x, y, MPFR_RNDN); 1396 MPFR_ASSERTN(mpfr_zero_p (z) && MPFR_IS_NEG (z)); 1397 } 1398 1399 mpfr_clear (x); 1400 mpfr_clear (y); 1401 mpfr_clear (z); 1402 mpfr_clear (max_val); 1403 1404 mpfr_set_emin (emin); 1405 mpfr_set_emax (emax); 1406 } 1407 1408 /* Bug found by Kevin P. Rauch */ 1409 static void 1410 bug20071218 (void) 1411 { 1412 mpfr_t x, y, z, t; 1413 int tern; 1414 1415 mpfr_inits2 (64, x, y, z, t, (mpfr_ptr) 0); 1416 mpfr_set_str (x, "0x.80000000000002P-1023", 0, MPFR_RNDN); 1417 mpfr_set_str (y, "100000.000000002", 16, MPFR_RNDN); 1418 mpfr_set_ui (t, 0, MPFR_RNDN); 1419 mpfr_nextabove (t); 1420 tern = mpfr_pow (z, x, y, MPFR_RNDN); 1421 if (mpfr_cmp0 (z, t) != 0) 1422 { 1423 printf ("Error in bug20071218 (1): Expected\n"); 1424 mpfr_dump (t); 1425 printf ("Got\n"); 1426 mpfr_dump (z); 1427 exit (1); 1428 } 1429 if (tern <= 0) 1430 { 1431 printf ("Error in bug20071218 (1): bad ternary value" 1432 " (%d instead of positive)\n", tern); 1433 exit (1); 1434 } 1435 mpfr_mul_2ui (y, y, 32, MPFR_RNDN); 1436 tern = mpfr_pow (z, x, y, MPFR_RNDN); 1437 if (MPFR_NOTZERO (z) || MPFR_IS_NEG (z)) 1438 { 1439 printf ("Error in bug20071218 (2): expected 0, got\n"); 1440 mpfr_dump (z); 1441 exit (1); 1442 } 1443 if (tern >= 0) 1444 { 1445 printf ("Error in bug20071218 (2): bad ternary value" 1446 " (%d instead of negative)\n", tern); 1447 exit (1); 1448 } 1449 mpfr_clears (x, y, z, t, (mpfr_ptr) 0); 1450 } 1451 1452 /* With revision 5429, this gives: 1453 * pow.c:43: assertion failed: !mpfr_integer_p (y) 1454 * This is fixed in revision 5432. 1455 */ 1456 static void 1457 bug20080721 (void) 1458 { 1459 mpfr_t x, y, z, t[2]; 1460 int inex; 1461 int rnd; 1462 int err = 0; 1463 1464 /* Note: input values have been chosen in a way to select the 1465 * general case. If mpfr_pow is modified, in particular line 1466 * if (y_is_integer && (MPFR_GET_EXP (y) <= 256)) 1467 * make sure that this test still does what we want. 1468 */ 1469 mpfr_inits2 (4913, x, y, (mpfr_ptr) 0); 1470 mpfr_inits2 (8, z, t[0], t[1], (mpfr_ptr) 0); 1471 mpfr_set_si (x, -1, MPFR_RNDN); 1472 mpfr_nextbelow (x); 1473 mpfr_set_ui_2exp (y, 1, mpfr_get_prec (y) - 1, MPFR_RNDN); 1474 inex = mpfr_add_ui (y, y, 1, MPFR_RNDN); 1475 MPFR_ASSERTN (inex == 0); 1476 mpfr_set_str_binary (t[0], "-0.10101101e2"); 1477 mpfr_set_str_binary (t[1], "-0.10101110e2"); 1478 RND_LOOP_NO_RNDF (rnd) 1479 { 1480 int i, inex0; 1481 1482 i = (rnd == MPFR_RNDN || rnd == MPFR_RNDD || rnd == MPFR_RNDA); 1483 inex0 = i ? -1 : 1; 1484 mpfr_clear_flags (); 1485 inex = mpfr_pow (z, x, y, (mpfr_rnd_t) rnd); 1486 1487 if (__gmpfr_flags != MPFR_FLAGS_INEXACT || ! SAME_SIGN (inex, inex0) 1488 || MPFR_IS_NAN (z) || mpfr_cmp (z, t[i]) != 0) 1489 { 1490 unsigned int flags = __gmpfr_flags; 1491 1492 printf ("Error in bug20080721 with %s\n", 1493 mpfr_print_rnd_mode ((mpfr_rnd_t) rnd)); 1494 printf ("expected "); 1495 mpfr_out_str (stdout, 2, 0, t[i], MPFR_RNDN); 1496 printf (", inex = %d, flags = %u\n", inex0, 1497 (unsigned int) MPFR_FLAGS_INEXACT); 1498 printf ("got "); 1499 mpfr_out_str (stdout, 2, 0, z, MPFR_RNDN); 1500 printf (", inex = %d, flags = %u\n", inex, flags); 1501 err = 1; 1502 } 1503 } 1504 mpfr_clears (x, y, z, t[0], t[1], (mpfr_ptr) 0); 1505 if (err) 1506 exit (1); 1507 } 1508 1509 /* The following test fails in r5552 (32-bit and 64-bit). This is due to: 1510 * mpfr_log (t, absx, MPFR_RNDU); 1511 * mpfr_mul (t, y, t, MPFR_RNDU); 1512 * in pow.c, that is supposed to compute an upper bound on exp(y*ln|x|), 1513 * but this is incorrect if y is negative. 1514 */ 1515 static void 1516 bug20080820 (void) 1517 { 1518 mpfr_exp_t emin; 1519 mpfr_t x, y, z1, z2; 1520 1521 emin = mpfr_get_emin (); 1522 mpfr_set_emin (MPFR_EMIN_MIN); 1523 mpfr_init2 (x, 80); 1524 mpfr_init2 (y, sizeof (mpfr_exp_t) * CHAR_BIT + 32); 1525 mpfr_init2 (z1, 2); 1526 mpfr_init2 (z2, 80); 1527 mpfr_set_ui (x, 2, MPFR_RNDN); 1528 mpfr_nextbelow (x); 1529 mpfr_set_exp_t (y, mpfr_get_emin () - 2, MPFR_RNDN); 1530 mpfr_nextabove (y); 1531 mpfr_pow (z1, x, y, MPFR_RNDN); 1532 mpfr_pow (z2, x, y, MPFR_RNDN); 1533 /* As x > 0, the rounded value of x^y to nearest in precision p is equal 1534 to 0 iff x^y <= 2^(emin - 2). In particular, this does not depend on 1535 the precision p. Hence the following test. */ 1536 if (MPFR_IS_ZERO (z1) && MPFR_NOTZERO (z2)) 1537 { 1538 printf ("Error in bug20080820\n"); 1539 exit (1); 1540 } 1541 mpfr_clears (x, y, z1, z2, (mpfr_ptr) 0); 1542 set_emin (emin); 1543 } 1544 1545 static void 1546 bug20110320 (void) 1547 { 1548 mpfr_exp_t emin; 1549 mpfr_t x, y, z1, z2; 1550 int inex; 1551 unsigned int flags; 1552 1553 emin = mpfr_get_emin (); 1554 mpfr_set_emin (11); 1555 mpfr_inits2 (2, x, y, z1, z2, (mpfr_ptr) 0); 1556 mpfr_set_ui_2exp (x, 1, 215, MPFR_RNDN); 1557 mpfr_set_ui (y, 1024, MPFR_RNDN); 1558 mpfr_clear_flags (); 1559 inex = mpfr_pow (z1, x, y, MPFR_RNDN); 1560 flags = __gmpfr_flags; 1561 mpfr_set_ui_2exp (z2, 1, 215*1024, MPFR_RNDN); 1562 if (inex != 0 || flags != 0 || ! mpfr_equal_p (z1, z2)) 1563 { 1564 printf ("Error in bug20110320\n"); 1565 printf ("Expected inex = 0, flags = 0, z = "); 1566 mpfr_dump (z2); 1567 printf ("Got inex = %d, flags = %u, z = ", inex, flags); 1568 mpfr_dump (z1); 1569 exit (1); 1570 } 1571 mpfr_clears (x, y, z1, z2, (mpfr_ptr) 0); 1572 set_emin (emin); 1573 } 1574 1575 static void 1576 tst20140422 (void) 1577 { 1578 mpfr_t x, y, z1, z2; 1579 int inex, rnd; 1580 unsigned int flags; 1581 1582 mpfr_inits2 (128, x, y, z1, z2, (mpfr_ptr) 0); 1583 mpfr_set_ui (x, 1296, MPFR_RNDN); 1584 mpfr_set_ui_2exp (y, 3, -2, MPFR_RNDN); 1585 mpfr_set_ui (z2, 216, MPFR_RNDN); 1586 RND_LOOP (rnd) 1587 { 1588 mpfr_clear_flags (); 1589 inex = mpfr_pow (z1, x, y, (mpfr_rnd_t) rnd); 1590 flags = __gmpfr_flags; 1591 if (inex != 0 || flags != 0 || ! mpfr_equal_p (z1, z2)) 1592 { 1593 printf ("Error in bug20140422 with %s\n", 1594 mpfr_print_rnd_mode ((mpfr_rnd_t) rnd)); 1595 printf ("Expected inex = 0, flags = 0, z = "); 1596 mpfr_dump (z2); 1597 printf ("Got inex = %d, flags = %u, z = ", inex, flags); 1598 mpfr_dump (z1); 1599 exit (1); 1600 } 1601 } 1602 mpfr_clears (x, y, z1, z2, (mpfr_ptr) 0); 1603 } 1604 1605 int 1606 main (int argc, char **argv) 1607 { 1608 mpfr_prec_t p; 1609 1610 tests_start_mpfr (); 1611 1612 bug20071127 (); 1613 special (); 1614 particular_cases (); 1615 check_pow_ui (); 1616 check_pow_si (); 1617 check_special_pow_si (); 1618 pow_si_long_min (); 1619 for (p = MPFR_PREC_MIN; p < 100; p++) 1620 check_inexact (p); 1621 underflows (); 1622 overflows (); 1623 overflows2 (); 1624 overflows3 (); 1625 x_near_one (); 1626 bug20071103 (); 1627 bug20071104 (); 1628 bug20071128 (); 1629 bug20071218 (); 1630 bug20080721 (); 1631 bug20080820 (); 1632 bug20110320 (); 1633 tst20140422 (); 1634 1635 test_generic (MPFR_PREC_MIN, 100, 100); 1636 test_generic_ui (MPFR_PREC_MIN, 100, 100); 1637 test_generic_si (MPFR_PREC_MIN, 100, 100); 1638 1639 data_check ("data/pow275", mpfr_pow275, "mpfr_pow275"); 1640 1641 bad_cases (powu2, root2, "mpfr_pow_ui[2]", 1642 8, -256, 255, 4, 128, 800, 40); 1643 bad_cases (pows2, root2, "mpfr_pow_ui[2]", 1644 8, -256, 255, 4, 128, 800, 40); 1645 bad_cases (powu3, root3, "mpfr_pow_ui[3]", 1646 8, -256, 255, 4, 128, 800, 40); 1647 bad_cases (pows3, root3, "mpfr_pow_ui[3]", 1648 8, -256, 255, 4, 128, 800, 40); 1649 bad_cases (powu4, root4, "mpfr_pow_ui[4]", 1650 8, -256, 255, 4, 128, 800, 40); 1651 bad_cases (pows4, root4, "mpfr_pow_ui[4]", 1652 8, -256, 255, 4, 128, 800, 40); 1653 bad_cases (powu5, root5, "mpfr_pow_ui[5]", 1654 8, -256, 255, 4, 128, 800, 40); 1655 bad_cases (pows5, root5, "mpfr_pow_ui[5]", 1656 8, -256, 255, 4, 128, 800, 40); 1657 bad_cases (powu17, root17, "mpfr_pow_ui[17]", 1658 8, -256, 255, 4, 128, 800, 40); 1659 bad_cases (pows17, root17, "mpfr_pow_ui[17]", 1660 8, -256, 255, 4, 128, 800, 40); 1661 bad_cases (powu120, root120, "mpfr_pow_ui[120]", 1662 8, -256, 255, 4, 128, 800, 40); 1663 bad_cases (pows120, root120, "mpfr_pow_ui[120]", 1664 8, -256, 255, 4, 128, 800, 40); 1665 1666 tests_end_mpfr (); 1667 return 0; 1668 } 1669