diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2017-12-18 15:06:45 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2017-12-18 15:06:45 +0000 |
commit | bfa641fd62d92aec1771111beb399747212e40e7 (patch) | |
tree | d07e3b094917b3542c7af24ba98a0775d6b930ca | |
parent | ec4e2d514350f79d32c0eb562b3b25864d837b09 (diff) | |
download | mpfr-bfa641fd62d92aec1771111beb399747212e40e7.tar.gz |
[src/div.c] fixed bug in mpfr_div2_approx()
[tests/tdiv.c] added non-regression test
[tests/ttan.c] added test triggering bug in mpfr_div2_approx()
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@12002 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | src/div.c | 3 | ||||
-rw-r--r-- | tests/tdiv.c | 17 | ||||
-rw-r--r-- | tests/ttan.c | 20 |
3 files changed, 39 insertions, 1 deletions
@@ -71,7 +71,8 @@ mpfr_div2_approx (mpfr_limb_ptr Q1, mpfr_limb_ptr Q0, /* we ignore yy below, but first increment r0, to ensure we get a lower approximation of the remainder */ - r0 += (yy != 0); + r0 += yy != 0; + r1 += r0 == 0 && yy != 0; r0 = u0 - r0; r1 = u1 - r1 - (r0 > u0); diff --git a/tests/tdiv.c b/tests/tdiv.c index 077347e66..5b0bb04e6 100644 --- a/tests/tdiv.c +++ b/tests/tdiv.c @@ -1479,11 +1479,28 @@ test_mpfr_div2_approx (unsigned long n) } #endif +/* bug found in ttan with GMP_CHECK_RANDOMIZE=1514257254 */ +static void +bug20171218 (void) +{ + mpfr_t s, c; + mpfr_init2 (s, 124); + mpfr_init2 (c, 124); + mpfr_set_str_binary (s, "-0.1110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110E0"); + mpfr_set_str_binary (c, "0.1111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111E-1"); + mpfr_div (c, s, c, MPFR_RNDN); + mpfr_set_str_binary (s, "-1.111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"); + MPFR_ASSERTN(mpfr_equal_p (c, s)); + mpfr_clear (s); + mpfr_clear (c); +} + int main (int argc, char *argv[]) { tests_start_mpfr (); + bug20171218 (); testall_rndf (9); test_20170105 (); check_inexact (); diff --git a/tests/ttan.c b/tests/ttan.c index 557168231..393acfe60 100644 --- a/tests/ttan.c +++ b/tests/ttan.c @@ -92,6 +92,25 @@ check_nans (void) mpfr_clear (y); } +/* This test was generated from bad_cases, with GMP_CHECK_RANDOMIZE=1514257254. + For the x value below, we have tan(x) = -1.875 + epsilon, + thus with RNDZ it should be rounded to -1.c. */ +static void +bug20171218 (void) +{ + mpfr_t x, y, z; + mpfr_init2 (x, 804); + mpfr_init2 (y, 4); + mpfr_init2 (z, 4); + mpfr_set_str (x, "-1.14b1dd5f90ce0eded2a8f59c05e72daf7cc4c78f5075d73246fa420e2c026291d9377e67e7f54e925c4aed39c7b2f917424033c8612f00a19821890558d6c2cef9c60f4ad2c3b061ed53a1709dc1ec8e139627c2119c36d7ebdff0d715e559b47f740c534", 16, MPFR_RNDN); + mpfr_tan (y, x, MPFR_RNDZ); + mpfr_set_str (z, "-1.c", 16, MPFR_RNDN); + MPFR_ASSERTN(mpfr_equal_p (y, z)); + mpfr_clear (x); + mpfr_clear (y); + mpfr_clear (z); +} + int main (int argc, char *argv[]) { @@ -102,6 +121,7 @@ main (int argc, char *argv[]) tests_start_mpfr (); + bug20171218 (); check_nans (); mpfr_init (x); |