On Jan 17, 2008 11:25 AM, Tracy R Reed <[EMAIL PROTECTED]> wrote:
> Chuck Esterbrook wrote:
> > One of my test cases even reads:
> >
> >     assert .1+.1+.1+.1+.1+.1+.1+.1+.1+.1 == 1.0
> >
> > Which fails in most languages including Python.
>
>  >>> assert .1+.1+.1+.1+.1+.1+.1+.1+.1+.1 == 1.0
> Traceback (most recent call last):
>    File "<stdin>", line 1, in ?
> AssertionError
>  >>> print .1+.1+.1+.1+.1+.1+.1+.1+.1+.1
> 1.0
>
> They both appear to come out to 1.0. Is the print statement doing some
> rounding as well or something?

You said "both", but only the print statement appears to come out 1.0.
The first throws an AssertionError when the comparison to 1.0 fails.

You can skip the "assert" and the "print" in which case you get the
repr() of the expression result:

>>> .1+.1+.1+.1+.1+.1+.1+.1+.1+.1
0.99999999999999989

What I find strange is that Python is so slow at runtime in the name
of doing things right and giving programmers lots of flexibility. Then
it gets addition wrong presumably for speed...

Python has a decimal module with Decimal class, but you have to use it
very explicitly.

Hmm, I realize I forgot to mention this in http://cobralang.com/docs/python/


-Chuck

-- 
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg

Reply via email to