don't NaN & infinities hide FP errors

Jeremy Bowers jerf at jerf.org
Wed Nov 17 20:49:06 EST 2004


On Wed, 17 Nov 2004 01:30:33 -0800, kartik wrote:

> Since Python floats are implemented using C doubles, assuming IEEE 754
> compliance, certain operations should result in NaN or infinity. Don't
> such special values hide errors? Would we want our variables to be in
> such states? I feel it would be better if a floating point division by
> zero (or other actions that produce NaNs or infinities) throws an
> exception, just like an integer divide by zero.
> 
> Am I right?

You may think, while dealing with your problems and programs, that NaN is
an error. 

I may want them, because NaN, Inf, and exceptions are not the same things.

If you're working with floats, you're *already* in a domain where
*everything* might hide an error. Along with everybody else's reply
(including Tim Peter's which should be considered "definitive"), I'd add
that trying to create a float-based system that *doesn't* "hide errors" is
basically a contradiction in terms. All you can do is make a few choices
about which errors you want.




More information about the Python-list mailing list