Skip to content

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

Closed
@numpy-gitbot

Description

@numpy-gitbot

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions