e vs exp()? / financial applications

Andrew Thompson andrew.thompson at ashecastle.com
Mon Sep 23 19:15:37 CEST 2002


One must be aware of the representational issues and accuracy of
arithmetic within a datatype when using numerical types.  This is not so
much a Python issue as one of representing the real number line with
float types.

For example, the following on Python 2.2.1 #34 running on Windows XP
Pro, Celeron Processor (probably different elsewhere)

W=0.89 / 4

Now evaluate

1+w+w+w+w

and 

w+w+w+w+1

which are both *different* according to the == operator, but for the
purposes of numerical accuracy are identical.

This behaviour is quite mild, but it shows the point that rounding
errors can easily creep in, and using == to test for equality is not
always sensible.

Caveat Emptor!









More information about the Python-list mailing list