[Numpy-discussion] Casting and promotion rules (e.g. int + uint64 => float)
sergio.callegari at gmail.com
Mon Mar 11 14:17:22 EDT 2013
Thanks for the explanation.
Chris Barker - NOAA Federal <chris.barker <at> noaa.gov> writes:
> There has been a lot of discussion about casting on this list in the
> last couple months -- I suggest you peruse that discussion and see
> what conclusions it has lead to.
I'll look at it. My message to the ml followed an invitation to do so
after I posted a bug about weird castings.
> > int + uint64 -> float
> I think the idea here is that an int can hold negative numbers, so you
> can't put it in a uint64 -- but you can't put a uint64 into a signed
> int64. A float64 can hold the range of numbers of both a int and
> uint64, so it is used, even though it can't hold the full precision
> of a uint64 (far from it!)
I understand the good intention. Yet, this does not follow the principle of
least surprise. This is not what most other languages (possibly following C)
would do and, most important, dealing with integers, one expects overflows and
wraparounds, not certainly a loss of precision.
Another issue is that the promotion rule breaks indexing
a = np.uint64(1)
b[a] -> 1 # OK
b[a+1] -> Error
I really would like to suggest changing this behavior.
More information about the NumPy-Discussion