Does Scientific Notation Mean Perl Accuracy?

I came across strange behavior in Perl. The following subtraction should result in zero as a result (what it does in Python):

print 7.6178E-01 - 0.76178
-1.11022302462516e-16

Why is this happening and how to avoid it?

PS The effect appears on "v5.10.0, built for x86_64-linux-gnu-thread-multi" (Ubuntu 9.04) and "v5.8.9 for darwin-2level" (Mac OS 10.6)

+2
source share
1 answer

It is not that scientific notation affects accuracy in the same way that binary notation constraints on floating point notations are affected. See Responses to perlfaq4 . This is a problem for any language that relies on a basic architecture for storing numbers.

, bignum.

+8

All Articles