e vs exp()? / financial applications

Terry Reedy tjreedy at udel.edu
Tue Sep 24 03:33:03 CEST 2002


"Andrew Thompson" <andrew.thompson at ashecastle.com> wrote in message
news:mailman.1032801271.6597.python-list at python.org...
> 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.
...
> W=0.89 / 4
> 1+w+w+w+w
> w+w+w+w+1
>
> which are both *different* according to the == operator, but for the
> purposes of numerical accuracy are identical.

Since 'W' != 'w' in Python, both give a NameError unless w defined
elsewise 8<).
However...
>>> w=.89/4
>>> w
0.2225
>>> 1+w+w+w+w
1.8899999999999997
>>> w+w+w+w+1
1.8900000000000001

Although w appears to be exactly represented, it must not be.  Cute
example.

Terry J. Reedy





More information about the Python-list mailing list