On 10/8/2012 12:47 PM, Guido van Rossum wrote:
this as well. Also, IIUC the IEEE library prescribes exceptions as well as return values; e.g. "man 3 log" on my OSX computer says that log(0) returns -inf as well as raise a divide-by-zero exception. So I think this is probably compliant with the standard -- one can decide to ignore the exceptions in certain contexts and honor them in others. (Probably even the 1/0 behavior can be defended this way.)
I agree. In C, as I remember, a function can both (passively) 'raise an exception' by setting errno *and* return a value. This requires the programmer to check for an exception, and forgetting to do so is a common bug. In Python, raising an exception actively aborts returning a value, so you had to choose one of the two behaviors.
Some other operations behave inconsistently:
2 * 10.**308
Traceback (most recent call last): File "<stdin>", line 1, in <module> OverflowError: (34, 'Result too large')
Probably the same. IEEE 754 may be more complex than you think!
Or this might be an accidental inconsistency, in that float multiplication was changed to return inf but pow was not. But I would be reluctant to fiddle with such details now.
Alexander, while I might have chosen to make nan == nan True, I consider it a near tossup with no happy resolution and would not change it now. Guido's explanation is pretty clear: he went with the IEEE standard as interpreted for Python by Tim Peters.