long double vs double
Solution 1:
Quoting from Wikipedia:
On the x86 architecture, most compilers implement long double as the 80-bit extended precision type supported by that hardware (sometimes stored as 12 or 16 bytes to maintain data structure .
and
Compilers may also use long double for a 128-bit quadruple precision format, which is currently implemented in software.
In other words, yes, a long double
may be able to store a larger range of values than a double
. But it's completely up to the compiler.
Solution 2:
For modern compilers on x64, Clang and GCC uses 16-byte double for long double
while VC++ uses 8-byte double. In other words, with Clang and GCC you get higher precision double but for VC++ long double
is same as double
. The modern x86 CPUs do support these 16-byte doubles so I think Clang and GCC are doing the right thing and allows you to access lower level hardware capability using higher level language primitives.