[Numpy-discussion] Integer Overflow?
Dave
dave.hirschfeld@gmail....
Tue Jul 14 08:16:31 CDT 2009
I got stung when taking an ordinary python integer to the power of a numpy
integer - the result wasn't what I was expecting (see below)!
Taking a wild guess I expect this is due to integer overflow (since it doesn't
show up with int64). When working with an int32 type one has to be aware of such
issues and I'm guessing the casting behaviour is a design decision, nevertheless
I thought I'd post to make others aware of such considerations.
HTH,
Dave
Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.
IPython 0.10.bzr.r1163 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.
In [2]: import numpy as np
In [3]: np.__version__
Out[3]: '1.4.0.dev7056'
In [4]: 10**-10
Out[4]: 1e-010
In [5]: 10**np.float32(-10)
Out[5]: 1e-010
In [6]: 10**np.int32(-10)
Out[6]: 7.0918695992859933e-010 ????????????????????????????????????
In [7]: 10**np.int32(-1)
Out[7]: 0.10000000000000001
In [8]: 10**np.int32(-2)
Out[8]: 0.01
In [9]: 10**np.int32(-3)
Out[9]: 0.001
In [10]: 10**np.int32(-4)
Out[10]: 0.0001
In [11]: 10**np.int32(-5)
Out[11]: 1.0000000000000001e-005
In [12]: 10**np.int32(-6)
Out[12]: 9.9999999999999995e-007
In [13]: 10**np.int32(-7)
Out[13]: 9.9999999999999995e-008
In [14]: 10**np.int32(-8)
Out[14]: 1e-008
In [15]: 10**np.int32(-9)
Out[15]: 1.0000000000000001e-009
More information about the NumPy-Discussion
mailing list