diff src/number-mp.c @ 1990:4f5e0297b73f

[xemacs-hg @ 2004-04-06 20:52:08 by james] Fix bignum_to_double so it actually gives the right answer.
author james
date Tue, 06 Apr 2004 20:52:20 +0000
parents 9c872f33ecbe
children e567417c2e5d
line wrap: on
line diff
--- a/src/number-mp.c	Tue Apr 06 20:50:39 2004 +0000
+++ b/src/number-mp.c	Tue Apr 06 20:52:20 2004 +0000
@@ -159,17 +159,18 @@
 bignum_to_double (bignum b)
 {
   short rem, sign;
-  double retval = 0.0;
+  double retval = 0.0, factor = 1.0;
   REGISTER unsigned int i;
   MINT *quo;
 
   sign = MP_MCMP (b, bignum_zero) < 0 ? -1 : 1;
   quo = MP_ITOM (sign);
   MP_MULT (b, quo, quo);
-  for (i = 0U; MP_MCMP(quo, bignum_zero) > 0; i++)
+  for (i = 0U; MP_MCMP (quo, bignum_zero) > 0; i++)
     {
       MP_SDIV (quo, 256, quo, &rem);
-      retval += rem * i * 256;
+      retval += rem * factor;
+      factor *= 256.0;
     }
   MP_MFREE (quo);
   return retval * sign;