summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2009-09-18 11:36:15 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2009-09-18 11:36:15 +0000
commitba14330128422fca15d2437d063cc8bc8af31110 (patch)
tree3d3178c0d8b42705d061703a96796c1fc1c2d0e4
parentb094053c5cced22f960da1d0089d5960844774ef (diff)
downloadmpfr-ba14330128422fca15d2437d063cc8bc8af31110.tar.gz
frac.c, tests/tfrac.c: fixed bug in mpfr_frac (the non-significant bits
in low limb were not cleared) and added testcase (this corresponds to changesets 6453 to 6456 in trunk). git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/2.4@6457 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--frac.c8
-rw-r--r--tests/tfrac.c24
2 files changed, 32 insertions, 0 deletions
diff --git a/frac.c b/frac.c
index f43e94215..cd7f934d1 100644
--- a/frac.c
+++ b/frac.c
@@ -112,6 +112,14 @@ mpfr_frac (mpfr_ptr r, mpfr_srcptr u, mp_rnd_t rnd_mode)
tp[tn] = k | ((un) ? mpn_lshift (tp + t0, up, un, sh) : (mp_limb_t) 0);
if (t0 > 0)
MPN_ZERO(tp, t0);
+ else
+ {
+ int tsh;
+
+ /* non-significant bits in low limb */
+ tsh = (mp_prec_t) tn * BITS_PER_MP_LIMB - MPFR_PREC(t);
+ tp[0] &= ~ MPFR_LIMB_MASK (tsh);
+ }
if (t != r)
{ /* t is tmp */
diff --git a/tests/tfrac.c b/tests/tfrac.c
index a0d7e9f2f..7f0e25c79 100644
--- a/tests/tfrac.c
+++ b/tests/tfrac.c
@@ -172,6 +172,28 @@ special (void)
mpfr_clear (t);
}
+static void
+bug20090918 (void)
+{
+ mpfr_t x, y;
+ mp_limb_t y0;
+
+ mpfr_init2 (x, 32);
+ mpfr_init2 (y, 13);
+ mpfr_set_str (x, "61680.352935791015625", 10, GMP_RNDN);
+ mpfr_frac (y, x, GMP_RNDZ);
+ y0 = MPFR_MANT(y)[0];
+ while ((y0 >> 1) << 1 == y0)
+ y0 >>= 1;
+ if (y0 > 0x2000)
+ {
+ printf ("Error in bug20090918 (significand has more than 13 bits).\n");
+ exit (1);
+ }
+ mpfr_clear (x);
+ mpfr_clear (y);
+}
+
#define TEST_FUNCTION mpfr_frac
#include "tgeneric.c"
@@ -227,6 +249,8 @@ main (void)
mpfr_clear (ip);
mpfr_clear (fp);
+ bug20090918 ();
+
test_generic (2, 1000, 10);
tests_end_mpfr ();