[Numpy-discussion] should abs gives negative at end of integer range?

Jonathan Wright wright@esrf...
Sun May 25 12:38:43 CDT 2008


This one comes up in a Java puzzler, but applies equally to numpy.

http://www.youtube.com/watch?v=wDN_EYUvUq0

 >>> import numpy, sys
 >>> abs(numpy.array([-sys.maxint-1],numpy.int)) > 0
array([False], dtype=bool)
 >>> abs(numpy.array([-129,-128,-127],numpy.int8)) > 0
array([ True, False,  True], dtype=bool)

... etc. Sort of surprising that abs gives something negative. Is this 
the intended behaviour as covered by a unit test and doc already?

-Jon



More information about the Numpy-discussion mailing list