[Pdx-pm] Unexpected math result

chromatic chromatic at wgz.org
Wed Dec 21 11:34:23 PST 2011


On Wednesday, December 21, 2011 at 11:31 AM, Michael R wrote:
 
>  Silly me would expect something like 0 to be printed.  Why the
> 2.16840434497101e-18?  (OK, round it off and you have 0, but ....) 

This is a feature of how computers usually represent floating point numbers. 
perlfaq4 points to David Goldberg's "What Every Computer Scientist Should Know 
About Floating-Point Arithmetic" at:

	http://web.cse.msu.edu/~cse320/Documents/FloatingPoint.pdf

The short of it is that you can't represent certain fractional components 
precisely with a powers-of-two representation.

-- c


More information about the Pdx-pm-list mailing list