Skip to content

scalars don't raise overflow/underflow/divbyzero/invalid (Trac #1671) #2267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
numpy-gitbot opened this issue Oct 19, 2012 · 4 comments
Closed

Comments

@numpy-gitbot
Copy link

Original ticket http://projects.scipy.org/numpy/ticket/1671 on 2010-11-11 by @mwiebe, assigned to unknown.

All these cases should be raising, I believe:

>>> import numpy as np
>>> err = np.seterr(all='raise')

>>> np.float32(1e-38) / np.float32(1e30)
0.0
>>> np.float32(1e-38) / np.array(1e38,np.float32)
0.0
>>> np.array(1e-38,np.float32) / np.float32(1e30)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FloatingPointError: underflow encountered in divide

>>> np.float64(1e-300) / np.float64(1e300)
0.0
>>> np.float64(1e-300) / np.array(1e300, dtype=np.float64)
0.0
>>> np.array(1e-300, dtype=np.float64) / np.float64(1e300)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FloatingPointError: underflow encountered in divide

>>> np.float32(1) / np.float32(0)
inf
>>> np.array(1,dtype=np.float32) / np.float32(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FloatingPointError: divide by zero encountered in divide

>>> np.inf-np.inf
nan
>>> np.array(np.inf)-np.inf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FloatingPointError: invalid value encountered in subtract
@numpy-gitbot
Copy link
Author

@mwiebe wrote on 2010-11-12

I dug in a little bit, and the problem appears to be the compiler optimizing too liberally. If I add a printf between the operation and PyUFunc_getfperr() in scalarmathmodule.c.src, it works.

    @name@_ctype_@oper@(arg1, arg2, &out);
    printf("Result is %g\n", out);
#endif

#if @fperr@
    /* Check status flag.  If it is set, then look up what to do */
    retstatus = PyUFunc_getfperr();

I'm guessing the compiler thinks it can reorder the float operation to after PyUFunc_getfperr, since PyUFunc_getfperr is independent of it except for the float exception state.

@numpy-gitbot
Copy link
Author

@mwiebe wrote on 2010-11-12

#13

@numpy-gitbot
Copy link
Author

@pv wrote on 2011-03-30

Seems to be fixed now. The changes were merged in 72a702d22cfcdba03

@numpy-gitbot
Copy link
Author

Milestone changed to 1.6.0 by @pv on 2011-03-30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant