On Thu, Oct 31, 2013 at 07:59:37AM -0700, via RT wrote: > Compare the following two commands. The first one thinks the > number is zero, the second one works fine. The whole difference > is an extra "0" in the mantissa. > > # echo 0.1530e-305 | perl -e '$v = <STDIN>; print "v=", $v + 0, "\n";' > v=0 > # echo 0.153e-305 | perl -e '$v = <STDIN>; print "v=", $v + 0, "\n";' > v=1.53e-306 > > The above is not supposed to underflow; there are still a couple of orders > of magnitude left: > # echo 0.1e-307 | perl -e '$v = <STDIN>; print "v=", $v + 0, "\n";' > v=9.99999999999999e-309 > > Observed with 5.16.0 > Not observed with 5.6.1 > Not observed with 5.12.4 > > Observed with OpenSuSE build (5.16.0). I've (hopefully) fixed it with the following commit, which I've just pushed for smoking: commit 07079ca1f145dc1ad3cfd0d9fa30d08871c79636 Author: David Mitchell <davem@iabyn.com> AuthorDate: Mon Dec 2 15:04:49 2013 +0000 Commit: David Mitchell <davem@iabyn.com> CommitDate: Mon Dec 2 15:04:49 2013 +0000 [perl #120426] atof() errors with trailing 0's For small numbers, trailing zeros in the fractional part of a floating-point literal could cause rounding to zero. From the bug report: $ echo 0.1530e-305 | perl -e '$v = <STDIN>; print "v=", $v + 0, "\n";' v=0 $ echo 0.153e-305 | perl -e '$v = <STDIN>; print "v=", $v + 0, "\n";' v=1.53e-306 I fixed this by stopping the processing of the integer or fractional component once its been detected that only zeroes are left (with a suitable adjustment of the exponent). -- print+qq&$}$"$/$s$,$a$d$g$s$@$.$q$,$:$.$q$^$,$@$a$~$;$.$q$m&if+map{m,^\d{0\,},,${$::{$'}}=chr($"+=$&||1)}q&10m22,42}6:17a2~2.3@3;^2dg3q/s"&=~m*\d\*.*gThread Previous | Thread Next