On 2010-01-11 12:27 PM, CELEN Erman wrote:
Numeric.log10() will check to see if the errno was set to ERANGE. It does not
check if a floating point exception flag was set, which is tricky to do across
platforms. The newer numpy can do it because we've finally managed to implement
all of that platform-specific code, but the earlier Numeric does not.
Presumably, the msvc8 C runtime's implementation of log10() sets errno and the
msvc9 runtime's version does not.

It doesn't seem like C part is changed. I confirmed that the behavior of 
log10(0.0) in C's standard math.h library didn't change between compilers 
(msvc8 and msvc9 both sets the errno to 34(ERANGE)). Now I'm thinking that this 
setting errno problem is happening somewhere in Numeric's log10 wrappers.

As I see, Numeric's "PyUFunc_GenericFunction" checks errno value to see if the called function has 
set it and if it is non-zero, it calls math_error which raises the exception. The problem is that now errno 
is not being set but I can't see why since I can't step into that redirected function call ("*(double 
*)op = ((DoubleUnaryFunc *)func)(*(double *)ip1)" where function value is "0x01c4ede0 log10").

This is the math library's log10() function.

I am wondering which functions are actually being called when I call 
log10(0.0). Could you (or anybody) point me where this errno is supposed to be 
set in Numeric or umath when I call log10(0.0) so that I can take a look at why 
this is not being the case.

errno gets set to 0 before PyUFunc_GenericFunction calls the underlying log10() function. Other than that, Numeric does not set errno.

(I also noticed that this behavior is same under standard NumPy 1.4 with standard Python 
2.6 on Windows. If you call numpy.log10(0.0) you will get an "-inf" and no 
exceptions will be raised. Which is not the case with Python's standard math.log10(0.0) 
which will raise a ValueError)

Correct. This is numpy's intended behavior. See numpy.seterr() to enable exceptions if you want them.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to