summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2018-01-10 16:48:57 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2018-01-10 16:48:57 +0000
commit78de98df9e17736900f342eaa16a5a36a60bd65e (patch)
tree64ae790ab5c688040c4976c65af0cc1752745209
parentcd2fb9c3fb3087e260712fd3a00d3ae4f5d0c814 (diff)
downloadmpfr-78de98df9e17736900f342eaa16a5a36a60bd65e.tar.gz
[src/ai.c] Fixed handling of reduced exponent range.
[tests/tai.c] Added corresponding test cases (in addition to what has been done in tgeneric.c). (merged changesets r12070-12072,12074-12075 from the trunk) git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/4.0@12094 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--src/ai.c4
-rw-r--r--tests/tai.c44
2 files changed, 46 insertions, 2 deletions
diff --git a/src/ai.c b/src/ai.c
index abfd0ec84..9f022e6c8 100644
--- a/src/ai.c
+++ b/src/ai.c
@@ -576,7 +576,6 @@ mpfr_ai2 (mpfr_ptr y, mpfr_srcptr x, mpfr_rnd_t rnd)
} /* End of ZIV loop */
MPFR_ZIV_FREE (loop);
- MPFR_SAVE_EXPO_FREE (expo);
r = mpfr_set (y, result, rnd);
@@ -592,7 +591,8 @@ mpfr_ai2 (mpfr_ptr y, mpfr_srcptr x, mpfr_rnd_t rnd)
mpfr_clear (temp1);
mpfr_clear (temp2);
- return r;
+ MPFR_SAVE_EXPO_FREE (expo);
+ return mpfr_check_range (y, r, rnd);
}
/* We consider that the boundary between the area where the naive method
diff --git a/tests/tai.c b/tests/tai.c
index 9df0c2a94..c6b82b20c 100644
--- a/tests/tai.c
+++ b/tests/tai.c
@@ -90,11 +90,55 @@ check_zero (void)
mpfr_clear (r);
}
+static void
+bug20180107 (void)
+{
+ mpfr_t x, y, z;
+ mpfr_exp_t emin;
+ int inex;
+ mpfr_flags_t flags;
+
+ mpfr_init2 (x, 152);
+ mpfr_init2 (y, 11);
+ mpfr_init2 (z, 11);
+ mpfr_set_str_binary (x, "0.11010101100111000111001001010110101001100001011110101111000010100111011101011110000100111011101100100100001010000110100011001000111010010001110000011100E5");
+ emin = mpfr_get_emin ();
+ mpfr_set_emin (-134);
+ mpfr_clear_flags ();
+ inex = mpfr_ai (y, x, MPFR_RNDA);
+ flags = __gmpfr_flags;
+ /* result should be 0.10011100000E-135 with unlimited exponent range,
+ and thus should be rounded to 0.1E-134 */
+ mpfr_set_str_binary (z, "0.1E-134");
+ MPFR_ASSERTN (mpfr_equal_p (y, z));
+ MPFR_ASSERTN (inex > 0);
+ MPFR_ASSERTN (flags == (MPFR_FLAGS_UNDERFLOW | MPFR_FLAGS_INEXACT));
+
+ mpfr_set_prec (x, 2);
+ mpfr_set_str_binary (x, "0.11E7");
+ mpfr_set_prec (y, 2);
+ mpfr_clear_flags ();
+ inex = mpfr_ai (y, x, MPFR_RNDA);
+ flags = __gmpfr_flags;
+ /* result should be 1.0E-908 with unlimited exponent range,
+ and thus should be rounded to 0.1E-134 */
+ mpfr_set_str_binary (z, "0.1E-134");
+ MPFR_ASSERTN (mpfr_equal_p (y, z));
+ MPFR_ASSERTN (inex > 0);
+ MPFR_ASSERTN (flags == (MPFR_FLAGS_UNDERFLOW | MPFR_FLAGS_INEXACT));
+
+ mpfr_set_emin (emin);
+ mpfr_clear (x);
+ mpfr_clear (y);
+ mpfr_clear (z);
+}
+
int
main (int argc, char *argv[])
{
tests_start_mpfr ();
+ bug20180107 ();
check_large ();
check_zero ();