math.nroot [was Re: A brief question.]

Steven D'Aprano steve at
Wed Jul 6 01:52:14 CEST 2005

On Tue, 05 Jul 2005 10:10:47 -0500, Terry Hancock wrote:

> I have to mention that the idea of a math package that 
> allows NaN to propagate as though it were a number 
> scares the willies out of me.  God help me if I were to use
> it on something like Engineering where lives might
> depend on the answer being right.

The whole point of propogating NaNs is that they ever go away. Instead of
putting hundreds of tests for error conditions all through your code, and
god help you if you miss some obscure error condition or put it in the
wrong place, you put one test at the very end: is the final result a NaN
or not?

Of course, the point is moot, since the IEEE standard allows you to
specify that errors are signalling or non-signalling (quiet). You can pick
the behaviour that suits the application.

> That'd be like having a math package that allowed,
> say 0/0 = 1 or Inf/Inf = 1.  

If I recall correctly, the IEEE standard requires both of those to return
NaN, which is really the only correct thing to do.


More information about the Python-list mailing list