I have recently become interested in learning about programming in c++, because I want to get a bit deeper understanding of the way computers work and handle instructions. I
From the patch that fixed this in earlier versions:
MinGW uses the Microsoft runtime DLL msvcrt.dll. Here lies a problem: while gcc creates 80 bits long doubles, the MS runtime accepts 64 bit long doubles only.
This bug happens to me when I use 4.8.1 revision 4 from MinGW-get (the most recent version it offers), but not when I use 4.8.1 revision 5.
So you are not using long double wrong (although there would be better accuracy to do long double lValue = 123.456789L
to make sure it doesn't take 123.456789 as a double, then cast it to a long double).
The easiest way to fix this would be to simply change the version of MinGW you are using to 4.9 or 4.7, depending on what you need (you can get 4.9 here).
If you are willing to instead use printf, you could change to printf("%Lf", ...)
, and either:
#define __USE_MINGW_ANSI_STDIO 1
before #include <cstdio>
(found this from the origional patch)Finally, you can even just cast to a double
whenever you try to print out the long double
(there is some loss of accuracy, but it shouldn't matter when just printing out numbers).
To find more details, you can also look at my blog post on this issue.
Update: If you want to continue to use Mingw 4.8, you can also just download a different distribution of Mignw, which didn't have that problem for me.