bug-gmp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

suggested patch re mpf x/x != 1 pb


From: Peter Moulder
Subject: suggested patch re mpf x/x != 1 pb
Date: 01 Jul 2001 15:39:50 +1000

The below patch Works For Me (i.e. mpf_div(x, x, x) results in exactly
1 even for x==1.9999...), and passes the regression tests.  However, I
haven't done a careful analysis of correctness, and I could have
introduced another bug that doesn't show up in the test suite.  I'd
also suggest adding to mpf/tests something like the program I sent in
the previous message, so that the bug doesn't re-appear when someone
decides to do "optimization".

pjm.

--- mpf/div.c-3.1.1     Mon Jul 24 17:04:19 2000
+++ mpf/div.c   Sun Jul  1 05:15:09 2001
@@ -68,10 +68,12 @@
   up = u->_mp_d;
   vp = v->_mp_d;
 
-  if (vsize > prec)
+  /* The `+ 1' below is to allow for a non-zero count of leading zeros, in
+     which case the shifted-in bits need to be from v instead of zeros. */
+  if (vsize > prec + 1)
     {
-      vp += vsize - prec;
-      vsize = prec;
+      vp += vsize - (prec + 1);
+      vsize = prec + 1;
     }
 
   tsize = vsize + prec;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]