[Edu-sig] re: expert floats

David Handy david at handysoftware.com
Thu Apr 8 17:51:59 EDT 2004


When I try this on Jython I get the following:

Jython 2.1 on java1.4.2_02 (JIT: null)
Type "copyright", "credits" or "license" for more information.
>>> 2.2 - 1.2 - 1.0
2.220446049250313E-16

As the various people on Python-dev said, no amount of display rounding
can cover up the fact that when you make the round trip between a string
and binary floating point, you lose something in the process.

I deal with that in my beginning programming book by contriving examples
that don't hit the weird cases (i.e. use 3.5, not 3.3) and plan on
relegating the details and explanations about floating-point
representation to a later section or an appendix.

I also have clear memories of encountering these same floating-point
conversion issues when programming in BASIC as a young teenager, and
dealing with it Ok. In particular, I learned not to rely on

IF A = B THEN ...

but rather

IF ABS(A - B) < DELTA THEN ...

BASIC was a great language to start with (before Python came along.)


On Wed, 7 Apr 2004, Rick Holbert wrote:

> When I try this using jython I get the following:
> 
> Jython 2.1 on java1.2.2 (JIT: sunwjit)
> Type "copyright", "credits" or "license" for more information.
> >>> 3.3
> 3.3
> >>>
> 
> _______________________________________________
> Edu-sig mailing list
> Edu-sig at python.org
> http://mail.python.org/mailman/listinfo/edu-sig
> 




More information about the Edu-sig mailing list