"Craig A. Berry" <craigberry@mac.com> wrote: :Urk. I found a case where this isn't right (or actually :lib/Math/Trig.t found a case where it isn't right): : :$ perl -e "my $x = 100.00000000000000001; print $x;" :100 : :so far so good, but now add another zero after the decimal: : :$ perl -e "my $x = 100.000000000000000001; print $x;" :0 Could you try the patch below? It doesn't break anything here, but I can't easily coerce my platform to use the new codepath. I can't remember if C offers anything closer to a perlish 'redo' than the <--i; continue;> used below. Hugo --- numeric.c.old Sun Jun 9 18:55:23 2002 +++ numeric.c Wed Jun 19 15:24:12 2002 @@ -902,9 +902,22 @@ } /* combine components of mantissa */ - for (i = 0; i <= ipart; ++i) - result += S_mulexp10((NV)part[ipart - i], + for (i = 0; i <= ipart; ++i) { + NV testresult = S_mulexp10((NV)part[ipart - i], i ? offcount + (i - 1) * PARTSIZE : 0); + if (testresult == 0.0 && part[ipart - i] != 0 && expextra < 0) { + /* since we calculate 100.001 as '100001 / 1000' we are in + danger of rounding to 0.0 rather than 100.0 if the + numerator overflows. Catch this, reduce precision, and redo + */ + result /= 10.0; + --offcount; + ++expextra; + --i; + continue; + } + result += testresult; + } if (seendigit && (*s == 'e' || *s == 'E')) { bool expnegative = 0;Thread Previous | Thread Next