Python fails on math

Nitin Pawar nitinpawar432 at gmail.com
Tue Feb 22 08:32:02 EST 2011


You may want to restrict the result to certain limit in the floating
numbers

each system has its own levels of floating numbers and even a small
difference is a difference to return FALSE

On Tue, Feb 22, 2011 at 6:50 PM, christian schulze <xcr4cx at googlemail.com>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)
> False
> [/code]
>
> So WTF? The equation is definitive equivalent. (See
> http://mathbin.net/59158)
>
> PS:
>
> #1:
> >>> 2.0 * e * sqrt(3.0) - 2.0 * e
> 3.9798408154464964
>
> #2:
> >>> 2.0 * e * (sqrt(3.0) -1.0)
> 3.979840815446496
>
> I was wondering what exactly is failing here. The math module? Python,
> or the IEEE specifications?
>
> --
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Nitin Pawar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110222/936d5adf/attachment-0001.html>


More information about the Python-list mailing list