Mercurial > hg > xemacs-beta
changeset 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 | 55bab11c30e8 |
children | d956f0da8a5e |
files | src/ChangeLog src/number-mp.c |
diffstat | 2 files changed, 8 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog Tue Apr 06 20:50:39 2004 +0000 +++ b/src/ChangeLog Tue Apr 06 20:52:20 2004 +0000 @@ -1,3 +1,7 @@ +2004-04-06 Jerry James <james@xemacs.org> + + * number-mp.c (bignum_to_double): Original algorithm was wrong. + 2004-04-06 Stephen J. Turnbull <stephen@xemacs.org> * lisp.h (Other numeric types): Band-aid: #define make_integer.
--- 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;