[Python-Dev] math.sqrt(-1) - NaN, ValueError or whatever you want?

Jack Jansen Jack.Jansen at cwi.nl
Thu Feb 5 15:44:07 EST 2004


The answers to my math questions never seem to stick, so I'm afraid I'm 
gonna have to ask this question again (even though I think I did the 
same a couple of years ago, but google doesn't find it).

It turns out that on MacOS math.sqrt(-1) returns "nan", as does 
math.log(-1), and I didn't try any other ones.

This is true for all possible combinations of MacPython 2.3, 2.4a0 or 
apple-Python 2.3, MacPython-OS9 or MacPython-OSX, and Mac OS 9 or Mac 
OS X.

When I tried the same on a linux box (Python 2.4a0) it raised 
ValueError: math domain error, which is what I would have expected.

Why this difference? Is it something I should fix? How? Or document it?
--
Jack Jansen, <Jack.Jansen at cwi.nl>, http://www.cwi.nl/~jack
If I can't dance I don't want to be part of your revolution -- Emma 
Goldman




More information about the Python-Dev mailing list