7

What is the actual precision of long double on Intel 64-bit platforms? is it 80 bits padded to 128 or actual 128 bit?

if former, besides going gmp, is there another option to achieve true 128 precision?

Z boson
  • 32,619
  • 11
  • 123
  • 226
Anycorn
  • 50,217
  • 42
  • 167
  • 261
  • Concerning ints, 128 bits precision arithmetic is available with gcc using `__int128_t` and `__uint_128_t` "types". – rafak May 10 '10 at 10:47
  • and for fp (gcc > 4.5) there is __float128 software-emulated-floating-point – osgx Aug 05 '11 at 03:08

4 Answers4

10

x86-64 precision is the same as regular x86. Extended double is 80 bits, using the x87 ISA, with 6 padding bytes added. There is no 128-bit FP hardware.

A software implementation of quad or extended quad precision might benefit from the x86-64 64x64 => 128 integer multiply instruction, though.

Potatoswatter
  • 134,909
  • 25
  • 265
  • 421
4

I would recommend using MPFR. It is a more sophisticated multiple-precision floating point library that is built on top of GMP.

casevh
  • 11,093
  • 1
  • 24
  • 35
2

There is a good chance that it's 64 bit for both (depending on the compiler and OS), because the compiler is emitting scalar SSE2 instead of x87 instructions.

x86 doesn't support higher precision than 80 bits, but if you really need more than 64 bits for a FP algorithm most likely you should check your numerics instead of solving the problem with brute force.

Axel Gneiting
  • 5,293
  • 25
  • 30
  • I am doing comparisons between using different precision and accuracy of result. – Anycorn May 10 '10 at 00:39
  • Have you ever observed such behavior? GCC, at least, I don't think can be prohibited from emitting x87. – Potatoswatter May 10 '10 at 00:45
  • 1
    Potatoswatter: Try `-msse2 -mfpmath=sse`, which should cause it to use SSE instructions for `double` and `float` s - although it likely still uses x87 instructions for `long double` s. – caf May 10 '10 at 01:05
  • 1
    Microsoft compilers all emit scalar SSE2. x87 is deprecated on Windows for x64 programs. I'm pretty sure that GCC does the same, because it's also faster and x64 CPUs are guaranteed to have support for SSE2. But there might be the case that it still emits x87 for long double. – Axel Gneiting May 10 '10 at 01:35
  • @caf: those are the default for x64, but no options affect `long double` that I see in the manpage. – Potatoswatter May 10 '10 at 03:32
  • 3
    The x86-64 ABI ( http://www.x86-64.org/documentation/abi.pdf ) actually specifies that `long double` is the x87's 80-bit extended precision format. – caf May 10 '10 at 04:16
  • Not all systems use the official ABI. – Axel Gneiting May 10 '10 at 10:59
1

I recommend the Boost wrappers over MPFR or GMP:

Boost 1.70: cpp_bin_float.

As well as arbitrary types to any desired precision, the following types are provided:

cpp_bin_float_single           (24 bits + mantissa = 32 bits)
cpp_bin_float_double           (53 bits + mantissa = 64 bits)
cpp_bin_float_double_extended  (64 bits + mantissa)
cpp_bin_float_quad             (113 bits + mantissa = 128 bits)
cpp_bin_float_oct              (237 bits) + mantissa = 256 bits)

Boost offers almost out-of-the-box functionality. Once compiled, all one needs to do is add a pointer within the Visual Studio project to the include and library directories.

Tested with Visual Studio 2017 + Boost v1.70.

See instructions to compile boost.

Contango
  • 76,540
  • 58
  • 260
  • 305