summaryrefslogtreecommitdiff
path: root/tests/texp2.c
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2007-06-21 14:16:17 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2007-06-21 14:16:17 +0000
commitf204b9571f3f7f4b8a5ed33d324bf082b6d2b393 (patch)
tree7c1f88c93b794d388e99e34afaa81c276ec99135 /tests/texp2.c
parent376096f04a5bd1e8e21b6c7dff3145968095de4d (diff)
downloadmpfr-f204b9571f3f7f4b8a5ed33d324bf082b6d2b393.tar.gz
exp2.c: use MPFR_SMALL_INPUT_AFTER_SAVE_EXPO instead of
MPFR_FAST_COMPUTE_IF_SMALL_INPUT since 1 (__gmpfr_one) isn't necessarily representable. tests/texp2.c: added overflowed_exp2_0 test. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@4565 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/texp2.c')
-rw-r--r--tests/texp2.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/tests/texp2.c b/tests/texp2.c
index 47ba741a3..dadd0f651 100644
--- a/tests/texp2.c
+++ b/tests/texp2.c
@@ -137,6 +137,84 @@ exp_range (void)
mpfr_clear (x);
}
+static void
+overflowed_exp2_0 (void)
+{
+ mpfr_t x, y;
+ int emax, i, inex, rnd, err = 0;
+ mp_exp_t old_emax;
+
+ old_emax = mpfr_get_emax ();
+
+ mpfr_init2 (x, 8);
+ mpfr_init2 (y, 8);
+
+ for (emax = -1; emax <= 0; emax++)
+ {
+ mpfr_set_ui_2exp (y, 1, emax, GMP_RNDN);
+ mpfr_nextbelow (y);
+ set_emax (emax); /* 1 is not representable. */
+ /* and if emax < 0, 1 - eps is not representable either. */
+ for (i = -1; i <= 1; i++)
+ RND_LOOP (rnd)
+ {
+ mpfr_set_si_2exp (x, i, -512 * ABS (i), GMP_RNDN);
+ mpfr_clear_flags ();
+ inex = mpfr_exp2 (x, x, rnd);
+ if ((i >= 0 || emax < 0 || rnd == GMP_RNDN || rnd == GMP_RNDU) &&
+ ! mpfr_overflow_p ())
+ {
+ printf ("Error in overflowed_exp2_0 (i = %d, rnd = %s):\n"
+ " The overflow flag is not set.\n",
+ i, mpfr_print_rnd_mode (rnd));
+ err = 1;
+ }
+ if (rnd == GMP_RNDZ || rnd == GMP_RNDD)
+ {
+ if (inex >= 0)
+ {
+ printf ("Error in overflowed_exp2_0 (i = %d, rnd = %s):\n"
+ " The inexact value must be negative.\n",
+ i, mpfr_print_rnd_mode (rnd));
+ err = 1;
+ }
+ if (! mpfr_equal_p (x, y))
+ {
+ printf ("Error in overflowed_exp2_0 (i = %d, rnd = %s):\n"
+ " Got ", i, mpfr_print_rnd_mode (rnd));
+ mpfr_print_binary (x);
+ printf (" instead of 0.11111111E%d.\n", emax);
+ err = 1;
+ }
+ }
+ else
+ {
+ if (inex <= 0)
+ {
+ printf ("Error in overflowed_exp2_0 (i = %d, rnd = %s):\n"
+ " The inexact value must be positive.\n",
+ i, mpfr_print_rnd_mode (rnd));
+ err = 1;
+ }
+ if (! (mpfr_inf_p (x) && MPFR_SIGN (x) > 0))
+ {
+ printf ("Error in overflowed_exp2_0 (i = %d, rnd = %s):\n"
+ " Got ", i, mpfr_print_rnd_mode (rnd));
+ mpfr_print_binary (x);
+ printf (" instead of +Inf.\n");
+ err = 1;
+ }
+ }
+ }
+ set_emax (old_emax);
+ }
+
+ if (err)
+ exit (1);
+ mpfr_clear (x);
+ mpfr_clear (y);
+}
+
int
main (int argc, char *argv[])
{
@@ -270,6 +348,8 @@ main (int argc, char *argv[])
mpfr_clear (x);
mpfr_clear (y);
+ overflowed_exp2_0 ();
+
tests_end_mpfr ();
return 0;
}