What is the internal accuracy of numpy.float128?

What precision does numpy.float128 do for internal? Is it __float128 or long double? (or something else!)

Potentiality may arise on the question if anyone knows: is it safe in C to drop __float128 by doubling (16 bytes), only with loss of precision? (this is for interacting with C lib, which works with long doubles).

Edit: in response to the comment, the Linux-3.0.0-14-generic-x86_64-with-Ubuntu-11.10-oneiric platform. Now, if numpy.float128 has different platform-specific accuracy, this is also useful knowledge for me!

Just to be clear, it is me who is interested in accuracy, not the size of the element.

+22
c python numpy
Jan 30 '12 at 10:38
source share
2 answers

We recommend using longdouble instead of float128 , as it is quite a mess , an ATM. Python will use it for float64 during initialization.

Inside numpy it can be double or long double. It is defined in npy_common.h and depends on your platform. I do not know if you can include it out of the box in the source code.

If you don't need performance in this part of your algorithm, a safer way would be to export it to a string and use strold after that.

+7
Jan 30 '12 at 12:45
source share

numpy.longdouble refers to any type that your C compiler calls long double . This is currently the only extended floating point type supported by numpy.

On x86-32 and x86-64, this is an 80-bit floating point type . On more exotic systems, this may be something else (IIRC on Sparc is the actual 128-bit IEEE float, and on PPC it is double-double ). (It may also depend on which OS and compiler you are using - for example, MSVC on Windows does not support any extended precision at all.)

Numpy also exports some name, such as numpy.float96 or numpy.float128 . Which of these names is exported depends on your platform / compiler, but everything you get always refers to the same base type as longdouble . In addition, these names are very misleading. They do not specify the 96- or 128-bit IEEE floating point format. Instead, they indicate the number of alignment bits used by the base type long double . So, for example, on x86-32, long double is 80 bits, but gets up to 96 bits to support 32-bit alignment, and numpy calls this float96 . On x86-64, the long double again the same 80-bit type, but now it is populated up to 128 bits to support 64-bit alignment, and numpy calls it float128 . There is no extra accuracy, just an extra addition.

Recommendation: ignore float96 / float128 , just use numpy.longdouble . Or even better, stick with doubles if you have no truly compelling reason. They will be faster, more portable, etc.

+37
Jun 10 '13 at
source share



All Articles