[NumPy-Tickets] [NumPy] #1670: type casting doesn't raise floating point overflow or underflow

NumPy Trac numpy-tickets@scipy....
Thu Nov 11 12:55:12 CST 2010


#1670: type casting doesn't raise floating point overflow or underflow
-----------------------+----------------------------------------------------
 Reporter:  m-paradox  |       Owner:  somebody
     Type:  defect     |      Status:  new     
 Priority:  normal     |   Milestone:  2.0.0   
Component:  Other      |     Version:  1.5.0   
 Keywords:             |  
-----------------------+----------------------------------------------------
 This leads to some surprising results, observe:

 {{{
 >>> import numpy as np
 >>> err = np.seterr(all='raise')
 >>> a = np.arange(5, dtype='f4')
 >>> a / 1e38
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
 FloatingPointError: underflow encountered in divide
 >>> a / 1e40
 array([ 0.,  0.,  0.,  0.,  0.], dtype=float32)
 >>> np.float32(1e38)
 9.9999997e+37
 >>> np.float32(1e40)
 inf
 >>> a / np.inf
 array([ 0.,  0.,  0.,  0.,  0.], dtype=float32)
 }}}

 I would expect a / 1e40 to raise an overflow (when 1e40 overflows to inf)
 instead of silently slipping through and causing underflows to zero.

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/1670>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list