[Numpy-discussion] float128 / longdouble on PPC - is it broken?

Matthew Brett matthew.brett@gmail....
Tue Oct 25 13:29:06 CDT 2011


Hi,

On Tue, Oct 25, 2011 at 11:14 AM, Pauli Virtanen <pav@iki.fi> wrote:
> 25.10.2011 19:45, Matthew Brett kirjoitti:
> [clip]
>>> or, in case the platform doesn't have powl:
>>>
>>>         long double x;
>>>         x = pow(2, 64);
>>>         x -= 1;
>>>         printf("%g %Lg\n", (double)x, x);
>>
>> Both the same as numpy:
>>
>> [mb312@jerry ~]$ gcc test.c
>> test.c: In function 'main':
>> test.c:5: warning: incompatible implicit declaration of built-in function 'powl'
>> [mb312@jerry ~]$ ./a.out
>> 1.84467e+19 3.68935e+19
>
> This result may indicate that it's the *printing* of long doubles that's
> broken. Note how the value cast as double prints the correct result,
> whereas the %Lg format code gives something wrong.

Ah - sorry - I see now what you were trying to do.

> Can you try to check this by doing something like:
>
> - do some set of calculations using np.longdouble in Numpy
>   (that requires the extra accuracy)
>
> - at the end, cast the result back to double

In [1]: import numpy as np

In [2]: res = np.longdouble(2)**64

In [6]: res / 2**32
Out[6]: 4294967296.0

In [7]: (res-1) / 2**32
Out[7]: 8589934591.9999999998

In [8]: np.float((res-1) / 2**32)
Out[8]: 4294967296.0

In [9]: np.float((res) / 2**32)
Out[9]: 4294967296.0

Thanks,

Matthew


More information about the NumPy-Discussion mailing list