Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why did Microsoft abandon long double data type? [closed]

A while ago I wrote a program which used some factorial functions. I used the long double data type to support "relative" big numbers.

Now, I changed from codeblocks to Visualstudio 2010, I was wondering why my program didn't work any more till I realized after some research that MS has abandonded the long double data type. Is there any special reason for this? To me it looks very like step backwards in terms of technology.

Is there any alternative to use? (I would also be happy with an alternative out of the boost library).

like image 756
Stephan Dollberg Avatar asked Aug 19 '11 11:08

Stephan Dollberg


1 Answers

I'm not sure why you think that long double was "abandoned", as it is part of the C++ Standard and therefore a compliant implementation must, well, implement it.

What they did "abandon" is long double overloads of mathematical functions, and they did this because:

In Win32 programming, however, the long double data type maps to the double, 64-bit precision data type.

which, in turn, along with long double in older VS versions being 80-bit, is because:

FP code generation has been switching to the use of SSE/SSE2/SSE3 instruction sets instead of the x87 FP stack since that is what both the AMD and Intel recent and future chip generations are focusing their performance efforts on. These instruction sets only support 32 and 64 bit FP formats.

Still, that they chose not to support these overloads, even with same-sized double and long double types (both could have been made 64-bit), is a shame because they are also part of the C++ Standard. But, well, that's Microsoft for you. Intently stubborn.

[n3290: 26.8]: In addition to the double versions of the math functions in <cmath>, C++ adds float and long double overloaded versions of these functions, with the same semantics.

However, although these overloads are essentially deprecated in Visual Studio, they are still available, so you should still be able to use them:

The Microsoft run-time library provides long double versions of the math functions only for backward compatibility.


Is there any alternative to use? (I would also be happy with an alternative out of the boost library).

It sounds to me like you have been relying on long double to support a specific range of numeric values, and have consequently run into regression issues when that has changed in a different toolchain.

If you have a specific numeric range requirement, use fixed-range integral types. Here you have a few options:

  • stdint.h - a C99 feature that some C++ toolchains support as an extension;
  • stdint.h - a C99 feature that Boost re-implements as a library;
  • cstdint - a C++0x feature that may be of use if you are writing C++0x code.
like image 186
Lightness Races in Orbit Avatar answered Sep 20 '22 14:09

Lightness Races in Orbit