[Numpy-discussion] assigning full precision values to longdouble scalars
sransom at nrao.edu
Tue Feb 25 17:52:59 EST 2014
So I have a need to use longdouble numpy scalars in an application, and
I need to be able to reliably set long-double precision values in them.
Currently I don't see an easy way to do that. For example:
In : numpy.longdouble("1.12345678901234567890")
Note the loss of those last couple digits.
In : numpy.float("1.12345678901234567890")
In : numpy.longdouble("1.12345678901234567890") -
And so internally they are identical.
In this case, the string appears to be converted to a C double (i.e.
numpy float) before being assigned to the numpy scalar. And therefore
it loses precision.
Is there a good way of setting longdouble values? Is this a numpy bug?
I was considering using a tiny cython wrapper of strtold() to do a
conversion from a string to a long double, but it seems like this is
basically what should be happening internally in numpy in the above example!
Scott M. Ransom Address: NRAO
Phone: (434) 296-0320 520 Edgemont Rd.
email: sransom at nrao.edu Charlottesville, VA 22903 USA
GPG Fingerprint: 06A9 9553 78BE 16DB 407B FFCA 9BFA B6FF FFD3 2989
More information about the NumPy-Discussion