[NumPy-Tickets] [NumPy] #1975: [Mixing integers and floats] : wrong results in algebraic equation
NumPy Trac
numpy-tickets@scipy....
Wed Nov 9 10:24:15 CST 2011
#1975: [Mixing integers and floats] : wrong results in algebraic equation
----------------------+-----------------------------------------------------
Reporter: bde | Owner: somebody
Type: defect | Status: closed
Priority: normal | Milestone: Unscheduled
Component: Other | Version: 1.5.1
Resolution: wontfix | Keywords:
----------------------+-----------------------------------------------------
Changes (by rkern):
* status: new => closed
* resolution: => wontfix
Comment:
`(12200**2) * (2**4)` is too large for a 32-bit int to hold. numpy types
follow their C semantics (two's complement arithmetic to be precise), so
the overflow int32 values become negative. Python int objects will
silently upcast to unbounded long objects when they overflow. That's why
you get the difference between using a Python int 2 and a numpy int32
array with a 2 in it.
Use `ar = ar.astype(float)` at the top of your function if you want to
make sure it is treated as a float as soon as possible.
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/1975#comment:1>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list