[Numpy-discussion] Possible bug: uint64 + int gives float64
Charles R Harris
charlesr.harris@gmail....
Sun Jun 13 11:19:50 CDT 2010
On Sun, Jun 13, 2010 at 9:20 AM, Pearu Peterson <pearu.peterson@gmail.com>wrote:
> On Sun, Jun 13, 2010 at 4:45 PM, Nadav Horesh <nadavh@visionsense.com>
> wrote:
> > int can be larger than numpy.int64 therefore it should be coerced to
> float64 (or float96/float128)
>
> Ok, I see. The results type is defined by the types of operands, not
> by their values. I guess
> this has been discussed earlier but with small operands this feature
> may be unexpected.
> For example, with the same rule the result of int64 + int should be
> float64 while currently
> it is int64.
>
>
It's the combination of unsigned with signed that causes the promotion. The
int64 type can't hold the largest values in uint64. Strictly speaking,
doubles can't hold either of the 64 bit integer types without loss of
precision but at least the degradation is more gradual. Another possibility
here would be to raise an error/warning because no suitable integer type is
available, that would be perhaps less surprising than the promotion to
float. IIRC, there is also a case where numeric arrays get promoted to
objects, but I don't see my old table of such things floating about at the
moment.
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100613/181c8f3f/attachment.html
More information about the NumPy-Discussion
mailing list