int main (void) { tests_start_mpfr (); mpfr_test_init (); #ifndef MPFR_DOUBLE_SPEC printf ("Warning! The MPFR_DOUBLE_SPEC macro is not defined. This means\n" "that you do not have a conforming C implementation and problems\n" "may occur with conversions between MPFR numbers and standard\n" "floating-point types. Please contact the MPFR team.\n"); #elif MPFR_DOUBLE_SPEC == 0 /* printf ("The type 'double' of your C implementation does not seem to\n" "correspond to the IEEE-754 double precision. Though code has\n" "been written to support such implementations, tests have been\n" "done only on IEEE-754 double-precision implementations and\n" "conversions between MPFR numbers and standard floating-point\n" "types may be inaccurate. You may wish to contact the MPFR team\n" "for further testing.\n"); */ printf ("The type 'double' of your C implementation does not seem to\n" "correspond to the IEEE-754 double precision. Such particular\n" "implementations are not supported yet, and conversions between\n" "MPFR numbers and standard floating-point types may be very\n" "inaccurate.\n"); printf ("FLT_RADIX = %ld\n", (long) FLT_RADIX); printf ("DBL_MANT_DIG = %ld\n", (long) DBL_MANT_DIG); printf ("DBL_MIN_EXP = %ld\n", (long) DBL_MIN_EXP); printf ("DBL_MAX_EXP = %ld\n", (long) DBL_MAX_EXP); #endif if (check_denorms ()) exit (1); check_inf_nan (); check_min(); check_max(); check_get_d_2exp_inf_nan (); tests_end_mpfr (); return 0; }
int main (void) { #ifdef MPFR_HAVE_FESETROUND mpfr_t half, x, y; mp_rnd_t rnd_mode; #endif mpfr_test_init (); #ifdef MPFR_HAVE_FESETROUND mpfr_init2(half, 2); mpfr_set_ui(half, 1, GMP_RNDZ); mpfr_div_2ui(half, half, 1, GMP_RNDZ); /* has exponent 0 */ mpfr_init2(x, 128); mpfr_init2(y, 128); for (rnd_mode = 0; rnd_mode <= 3; rnd_mode++) { int i, j, si, sj; double di, dj; mpfr_set_machine_rnd_mode (rnd_mode); for (i = 1, di = 0.25; i < 127; i++, di *= 0.5) for (si = 0; si <= 1; si++) { mpfr_div_2ui (x, half, i, GMP_RNDZ); (si ? mpfr_sub : mpfr_add)(x, half, x, GMP_RNDZ); /* x = 1/2 +/- 1/2^(1+i) */ for (j = i+1, dj = di * 0.5; j < 128 && j < i+53; j++, dj *= 0.5) for (sj = 0; sj <= 1; sj++) { double c, d, dd; int exp; char *f; mpfr_div_2ui (y, half, j, GMP_RNDZ); (sj ? mpfr_sub : mpfr_add)(y, x, y, GMP_RNDZ); /* y = 1/2 +/- 1/2^(1+i) +/- 1/2^(1+j) */ exp = (LONG_RAND() % 47) - 23; mpfr_mul_2si (y, y, exp, GMP_RNDZ); if (mpfr_inexflag_p()) { fprintf(stderr, "Error in tget_d: inexact flag for " "(i,si,j,sj,rnd,exp) = (%d,%d,%d,%d,%d,%d)\n", i, si, j, sj, rnd_mode, exp); exit(1); } dd = si != sj ? di - dj : di + dj; d = si ? 0.5 - dd : 0.5 + dd; if ((LONG_RAND() / 1024) & 1) { c = mpfr_get_d (y, rnd_mode); f = "mpfr_get_d"; } else { exp = (LONG_RAND() % 47) - 23; c = mpfr_get_d3 (y, exp, rnd_mode); f = "mpfr_get_d3"; if (si) /* then real d < 0.5 */ d *= sj && i == 1 ? 4 : 2; /* normalize real d */ } if (exp > 0) d *= 1 << exp; if (exp < 0) d /= 1 << -exp; if (c != d) { fprintf (stderr, "Error in tget_d (%s) for " "(i,si,j,sj,rnd,exp) = (%d,%d,%d,%d,%d,%d)\n" "got %.25Le instead of %.25Le\n" "Difference: %.19e\n", f, i, si, j, sj, rnd_mode, exp, (long double) c, (long double) d, d - c); exit (1); } } } } mpfr_clear(half); mpfr_clear(x); mpfr_clear(y); #endif if (check_denorms ()) exit (1); return 0; }