summaryrefslogtreecommitdiff
path: root/tests/turandom.c
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2017-09-01 15:24:42 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2017-09-01 15:24:42 +0000
commitb4d1e77c10bdea1fc35a60b4546fe5cf22efd3ae (patch)
tree71278862c87bd7e7a5bc85e3519267c7a27f216c /tests/turandom.c
parentb305244b5f4d604652ead4729176fca0c66a2811 (diff)
downloadmpfr-b4d1e77c10bdea1fc35a60b4546fe5cf22efd3ae.tar.gz
[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
Diffstat (limited to 'tests/turandom.c')
-rw-r--r--tests/turandom.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/turandom.c b/tests/turandom.c
index 71d534918..191d9e585 100644
--- a/tests/turandom.c
+++ b/tests/turandom.c
@@ -345,6 +345,39 @@ underflow_tests (void)
}
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)
{
mpfr_t x;
@@ -630,6 +663,8 @@ main (int argc, char *argv[])
reprod_abi ();
#endif
+ test_underflow (verbose);
+
tests_end_mpfr ();
return 0;
}