Python fails on math

Jean-Michel Pichavant jeanmichel at
Tue Feb 22 15:24:41 CET 2011

christian schulze wrote:
> Hey guys,
> I just found out, how much Python fails on simple math. I checked a
> simple equation for a friend.
> [code]
>>>> from math import e as e
>>>> from math import sqrt as sqrt
>>>> 2*e*sqrt(3) - 2*e == 2*e*(sqrt(3) - 1)
e has no accurate representation in computer science.  Neither does it 
with the classic decimal representation. Same for pi, if you remember 
your math classes ;).

Quoting wikipedia, e known digits:
Date               Decimal digits            Computation performed by
2010 July 5    1,000,000,000,000    Shigeru Kondo & Alexander J. Ye

Anyway, no one solves equation by numerical application. If you want to 
illustrate that ab - ac = a(b-c), do it with integers, as their 
representation in computer science is accurate within a given range.


More information about the Python-list mailing list