[Numpy-tickets] [NumPy] #507: invalid math result in numpy.sqrt() and numpy.square() when using 2^32 and (2^32)^2

NumPy numpy-tickets@scipy....
Fri Apr 27 16:01:10 CDT 2007


#507: invalid math result in numpy.sqrt() and numpy.square() when using 2^32 and
(2^32)^2
----------------------+-----------------------------------------------------
 Reporter:  Xiph1980  |       Owner:  somebody
     Type:  defect    |      Status:  new     
 Priority:  high      |   Milestone:          
Component:  Other     |     Version:  none    
 Severity:  critical  |    Keywords:          
----------------------+-----------------------------------------------------
 I encountered this error a little while ago, and I couldn't find it
 already mentioned in other tickets.[[BR]]
 I apologise if I totally misplaced this bug-report or made any other
 mistakes, but this is the best place I've found so far to report this :)

 I'm not a programmer so I don't know where or how the error occurs, but
 with numpy.square weird stuff starts to happen in the area of 2^32^ where
 I first encountered it, for example, numpy.square((2**32)-1) gives the
 negative number -8589934591, and numpy.square((2**32)+1) gives 2^32^ * 2 +
 1 as answer. Obviously this isn't correct...[[BR]]
 I filed this as critical since numpy.square() just gives a false result,
 and not an error to attend the programmer that something's going pretty
 wrong.


 Following is a direct copy from the interpreter window where the error how
 I encountered it, shows in lines 12-17. Also can be seen by the test in
 line 18-19 with the sqrt function in math that that version of sqrt
 doesn't bug out.
 {{{
 Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)]
 on win
 32
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import numpy
 >>> import math
 >>> print numpy.__version__
 1.0.2
 >>> 2**32
 4294967296L
 >>> (2**32)**2
 18446744073709551616L
 >>> numpy.square(2**32)
 0
 >>> numpy.sqrt((2**32)**2)
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
 AttributeError: 'long' object has no attribute 'sqrt'
 >>> math.sqrt((2**32)**2)
 4294967296.0
 }}}

 After a bit of fiddling, it seems that 9223372036854775807 is the largest
 number for with numpy.sqrt() works before it passing on the abovementioned
 AttributeError.


 Systemspecs:[[BR]]
 AMD Athlon 64 3200+[[BR]]
 2 * 512MB DDR[[BR]]
 Windows XP 32bit[[BR]]
 Python 2.5[[BR]]
 numpy 1.02[[BR]]

-- 
Ticket URL: <http://projects.scipy.org/scipy/numpy/ticket/507>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.


More information about the Numpy-tickets mailing list