From b4d1e77c10bdea1fc35a60b4546fe5cf22efd3ae Mon Sep 17 00:00:00 2001 From: vlefevre Date: Fri, 1 Sep 2017 15:24:42 +0000 Subject: [tests/turandom.c] Added test_underflow(). (merged changesets r11691-11694 from the 3.1 branch) git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@11695 280ebfd0-de03-0410-8827-d642c229c3f4 --- tests/turandom.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'tests/turandom.c') diff --git a/tests/turandom.c b/tests/turandom.c index 71d534918..191d9e585 100644 --- a/tests/turandom.c +++ b/tests/turandom.c @@ -344,6 +344,39 @@ underflow_tests (void) mpfr_clear (x); } +static void +test_underflow (int verbose) +{ + mpfr_t x; + mpfr_exp_t emin = mpfr_get_emin (); + long i, exp[6] = {0, 0, 0, 0, 0, 0}; + + mpfr_init2 (x, 2); + mpfr_set_emin (-3); +#define N 1000000 + for (i = 0; i < N; i++) + { + mpfr_urandom (x, RANDS, MPFR_RNDN); + if (mpfr_zero_p (x)) + exp[5] ++; + else + /* exp=1 is possible if the generated number is 0.111111... */ + exp[1-mpfr_get_exp(x)] ++; + } + if (verbose) + printf ("exp=1:%.3f(%.3f) 0:%.3f(%.3f) -1:%.3f(%.3f) -2:%.3f(%.3f) " + "-3:%.3f(%.3f) zero:%.3f(%.3f)\n", + 100.0 * (double) exp[0] / (double) N, 12.5, + 100.0 * (double) exp[1] / (double) N, 43.75, + 100.0 * (double) exp[2] / (double) N, 21.875, + 100.0 * (double) exp[3] / (double) N, 10.9375, + 100.0 * (double) exp[4] / (double) N, 7.8125, + 100.0 * (double) exp[5] / (double) N, 3.125); + mpfr_clear (x); + mpfr_set_emin (emin); +#undef N +} + static void overflow_tests (void) { @@ -630,6 +663,8 @@ main (int argc, char *argv[]) reprod_abi (); #endif + test_underflow (verbose); + tests_end_mpfr (); return 0; } -- cgit v1.2.1