Problem with long double

Hello ! This is my first time on the forum, I have done a quick search of this topic on google but didn't find an answer. Here is the code

1
2
3
4
5
6
7
8
9
10
11
12
13
long double ld = 60.0L;
double d = 60.0L;
cout << ld << " " << d << endl;
ld = 60.0;
d = 60.0;
cout << ld << " " << d << endl;
ld = 60;
d = 60;
cout << ld << " " << d << endl;
cout << 60 << endl;
cout << 60.0 << endl;
cout << 60.0L << endl;
cout << (double)60.0L << endl;


Here is the output (problem)
1.13259e-317 60
1.13259e-317 60
1.13259e-317 60
60
60
1.13259e-317
60


I ran into this when I was trying to use long double for simple calculations and output and so I am trying to find out what is wrong. I don't understand where this behaviour comes from. It appears to be a problem with cout displaying long double variables. Is it the compiler ?
I am using the Dev-C++ 5.2.0.3 package which I think uses some version of MinGW 4.6, including C++11 support.
Yeah I just ran your code using codeblocks and the output for me was:

60  60
60  60
60  60
60
60
60
60


I don't know much about compilers but it could be dev-c. I've have heard dev-c has some issues....as does all compilers. Maybe play with the settings.
but 1.13259e-317 is such a ridiculously small number compared to 60.00
i'm thinking that it could be your code rather than the compiler (it's like an unitialised variable)
Last edited on
Thank you for your replies! I am using Dev-C because I was looking for C++11 support and wanted to avoid Visual Studio and its .Net framework (I suspect having it installed is crashing my system).
Dev-C++ is a recent revival of the 2005 name. I couldn't set up MinGW with another IDE while Dev-C++ came packaged.

It appears that converting a long double variable or constant literal into double before displaying it with cout makes things work. Behind it, operations like adding, multiplying, etc., seem to go normally for long doubles.
Topic archived. No new replies allowed.