don't NaN & infinities hide FP errors

Jive someone at microsoft.com
Sat Nov 20 22:16:22 EST 2004


I kind of like the various flavors of NaN.  I have on occasion written
numerical code that exploits them.  But seeing as how Python aspires to some
level of cross-platform portability, it really should throw exceptions
rather than return NaN's, Inf's, and the lot.  I am surprised that it
doesn't always do that.

jdadson at yahoo dott com

"Tim Peters" <tim.peters at gmail.com> wrote in message
news:mailman.6482.1100699355.5135.python-list at python.org...
> [Peter Maas]
> > Just try it. 1./0. raises a ZeroDivisionError,
>
> That much is true -- Python forces this.
>
> > math.log(0) raises a math range error, and math.log(-1) yields nan.
>
> The rest varies across platforms, as explained in this note at the end
> of Python's math module docs:
>
> """
> The math module consists mostly of thin wrappers around the platform C
> math library functions. Behavior in exceptional cases is loosely
> specified by the C standards, and Python inherits much of its
> math-function error-reporting behavior from the platform C
> implementation. As a result, the specific exceptions raised in error
> cases (and even whether some arguments are considered to be
> exceptional at all) are not defined in any useful cross-platform or
> cross-release way. For example, whether math.log(0) returns -Inf or
> raises ValueError or OverflowError isn't defined, and in cases where
> math.log(0) raises OverflowError, math.log(0L) may raise ValueError
> instead.
> """





More information about the Python-list mailing list