summaryrefslogtreecommitdiff
path: root/tests/tmul_2exp.c
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2011-02-18 11:37:39 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2011-02-18 11:37:39 +0000
commitdb6356c746bbfa0d3a876e7331792d783abe9953 (patch)
tree8e9845e4c6e477a5af477c4b9b9cdccca6801328 /tests/tmul_2exp.c
parent214b5076978efdc79e6bc4fd42af1640981fc985 (diff)
downloadmpfr-db6356c746bbfa0d3a876e7331792d783abe9953.tar.gz
[tests/tmul_2exp.c] Added a testcase showing a bug in mpfr_mul_2si
(possible intermediate overflow). git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@7475 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tmul_2exp.c')
-rw-r--r--tests/tmul_2exp.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/tmul_2exp.c b/tests/tmul_2exp.c
index 0d2c1e3fe..360573593 100644
--- a/tests/tmul_2exp.c
+++ b/tests/tmul_2exp.c
@@ -133,6 +133,63 @@ underflow0 (void)
underflow (MPFR_EMIN_MIN);
}
+static void
+large (mpfr_exp_t e)
+{
+ mpfr_t x, y, z;
+ mpfr_exp_t emax;
+ int inex;
+ unsigned int flags;
+
+ emax = mpfr_get_emax ();
+ set_emax (e);
+ mpfr_init2 (x, 8);
+ mpfr_init2 (y, 8);
+ mpfr_init2 (z, 4);
+
+ mpfr_set_inf (x, 1);
+ mpfr_nextbelow (x);
+
+ mpfr_mul_2si (y, x, -1, MPFR_RNDU);
+ mpfr_prec_round (y, 4, MPFR_RNDU);
+
+ mpfr_clear_flags ();
+ inex = mpfr_mul_2si (z, x, -1, MPFR_RNDU);
+ flags = __gmpfr_flags;
+
+ if (inex <= 0 || flags != MPFR_FLAGS_INEXACT || ! mpfr_equal_p (y, z))
+ {
+ printf ("Error in large(");
+ if (e == MPFR_EMAX_MAX)
+ printf ("MPFR_EMAX_MAX");
+ else if (e == emax)
+ printf ("default emax");
+ else if (e <= LONG_MAX)
+ printf ("%ld", (long) e);
+ else
+ printf (">LONG_MAX");
+ printf (")\nExpected inex > 0, flags = %u,\n y = ",
+ (unsigned int) MPFR_FLAGS_INEXACT);
+ mpfr_dump (y);
+ printf ("Got inex = %d, flags = %u,\n y = ",
+ inex, flags);
+ mpfr_dump (z);
+ exit (1);
+ }
+
+ mpfr_clears (x, y, z, (mpfr_ptr) 0);
+ set_emax (emax);
+}
+
+static void
+large0 (void)
+{
+ large (256);
+ if (mpfr_get_emax () != MPFR_EMAX_MAX)
+ large (mpfr_get_emax ());
+ large (MPFR_EMAX_MAX);
+}
+
int
main (int argc, char *argv[])
{
@@ -223,6 +280,7 @@ main (int argc, char *argv[])
mpfr_clears (w, z, (mpfr_ptr) 0);
underflow0 ();
+ large0 ();
tests_end_mpfr ();
return 0;