On 12/3/2014 8:44 AM, Matthew Brett wrote:
Hi,
I just noticed this using Christophe Gohlke's MKL builds of numpy:
import numpy as np val = 2**63 + 2**62 np.float64(val) 1.3835058055282164e+19 np.float64(val).astype(np.uint64) 9223372036854775808
In general it seems that floats get clipped at 2**63 when casting to uint64. This appears to be a bug in MSVS express 2010 (the only version I tested):
<test_cast.c> #include <stdio.h> #include <math.h>
int main(int argc, char* argv[]) { double fval = pow(2, 63) + pow(2, 11); double fval2; unsigned long long int ival = fval; fval2 = ival; printf("Float %f\n", fval); printf("Integer %f\n", fval2); printf("sizeof ulong %u\n", sizeof(unsigned long long int)); } </test_cast.c>
Z:\>test_cast.exe Float 9223372036854777900.000000 Integer 9223372036854775800.000000 sizeof ulong 8
I realize there's nothing much numpy can do about this, just thought I'd let y'all know.
Cheers,
Matthew
This is a know issue with older (<= 2010) 32 bit msvc, which uses x87 instead of SSE instructions. See also <https://github.com/scipy/scipy/blob/master/scipy/ndimage/tests/test_datatype...>. Christoph