summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2016-05-30 07:55:29 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2016-05-30 07:55:29 +0000
commit2470a4cca02091e150ae6f283be44d080425afc6 (patch)
treec9e42bcf9b1ca3e7e9d336c74bf28f56534073d3
parent7807ff7fee826a0fb271a0ad87892e0c7c9144fc (diff)
downloadmpfr-2470a4cca02091e150ae6f283be44d080425afc6.tar.gz
[tests/tsub.c] Added comments for check_max_almosteven.
(merged changeset r10386 from the trunk) git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/3.1@10387 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--tests/tsub.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/tsub.c b/tests/tsub.c
index 260ca107b..af4bc4a29 100644
--- a/tests/tsub.c
+++ b/tests/tsub.c
@@ -630,6 +630,26 @@ check_rounding (void)
}
}
+/* Check a = b - c, where the significand of b has all 1's, c is small
+ compared to b, and PREC(a) = PREC(b) - 1. Thus b is a midpoint for
+ the precision of the result a. The test is done with the extended
+ exponent range and with some reduced exponent range. Two choices
+ are made for the exponent of b: the maximum exponent - 1 (similar
+ to some normal case) and the maximum exponent (overflow case or
+ near overflow case, depending on the rounding mode).
+ This test is useful to trigger a bug in r10382: Since c is small,
+ the computation in sub1.c was done by first rounding b in the
+ precision of a, then correcting the result if b was a breakpoint
+ for this precision (exactly representable number for the directed
+ rounding modes, or midpoint for the round-to-nearest mode). The
+ problem was that for a midpoint in the round-to-nearest mode, the
+ rounding of b gave a spurious overflow; not only the overflow flag
+ was incorrect, but the result could not be corrected, since due to
+ this overflow, the "even rounding" information was lost.
+ In the case of reduced exponent range, an additional test is done
+ for consistency checks: the subtraction is done in the extended
+ exponent range (no overflow), then the result is converted to the
+ initial exponent range with mpfr_check_range. */
static void
check_max_almosteven (void)
{
@@ -669,6 +689,7 @@ check_max_almosteven (void)
unsigned int flags1, flags2;
int inex1, inex2;
+ /* Expected result. */
flags1 = MPFR_FLAGS_INEXACT;
if (rnd == MPFR_RNDN || MPFR_IS_LIKE_RNDZ (rnd, neg))
{
@@ -690,6 +711,7 @@ check_max_almosteven (void)
}
MPFR_SET_SIGN (a1, neg ? -1 : 1);
+ /* Computed result. */
mpfr_clear_flags ();
inex2 = mpfr_sub (a2, b, c, (mpfr_rnd_t) rnd);
flags2 = __gmpfr_flags;
@@ -717,6 +739,7 @@ check_max_almosteven (void)
if (i == 0)
break;
+ /* Additional test for the reduced exponent range. */
mpfr_clear_flags ();
set_emin (MPFR_EMIN_MIN);
set_emax (MPFR_EMAX_MAX);