I recently became interested in learning about C ++ programming because I want to understand a little more deeply how computers work and process instructions. I thought I would try data types, but I really don't understand what happens to my output ...
#include <iostream> #include <iomanip> using namespace std; int main() { float fValue = 123.456789; cout << setprecision(20) << fixed << fValue << endl; cout << "Size of float: " << sizeof(float) << endl; double dValue = 123.456789; cout << setprecision(20) << fixed << dValue << endl; cout << "Size of double: " << sizeof(double) << endl; long double lValue = 123.456789; cout << setprecision(20) << fixed << lValue << endl; cout << "Size of long double: " << sizeof(long double) << endl; return 0; }
The result that I expected would be something like this:
123.45678710937500000000 Size of float: 4 123.45678900000000000000 Size of double: 8 123.45678900000000000000 Size of long double: 16
This is my actual conclusion:
123.45678710937500000000 Size of float: 4 123.45678900000000000000 Size of double: 8 -6518427077408613100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.00000000000000000000 Size of long double: 12
Any ideas on what happened would be much appreciated, thanks!
Edit:
System: Windows 10 Pro Technical Preview 64-bit Operating System, x64-based processor Eclipse CDT 8.5

source share