[NumPy-Tickets] [NumPy] #1799: assert_approx_equal against 0.0 always fails

NumPy Trac numpy-tickets@scipy....
Fri Apr 15 18:24:49 CDT 2011


#1799: assert_approx_equal against 0.0 always fails
---------------------------+------------------------------------------------
 Reporter:  jaety          |       Owner:  somebody   
     Type:  defect         |      Status:  new        
 Priority:  normal         |   Milestone:  Unscheduled
Component:  numpy.testing  |     Version:  1.5.1      
 Keywords:                 |  
---------------------------+------------------------------------------------
 The following lines
 {{{
 import numpy as np
 np.testing.assert_approx_equal(0.0, 0.000000000000001)
 }}}
 returns that the two values are not equal to 7 significant digits.
 Basically, assert_approx_equal will fail incorrectly if either of the two
 numbers is identically 0.0, regardless of the number of significant digits
 you specify, because of the way the floating point numbers are scaled
 prior to testing them.

 I think you need an explicit test for 0.0, something like
 {{{
     # Specially handle desired or actual identically zero
     if ((desired==0.0 or actual==0.0) and
          np.abs(desired+actual)*np.power(10,significant)>=1.0):
         raise AssertionError(msg)
     else:
         return
 }}}

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


More information about the NumPy-Tickets mailing list