Was ist das C++-Suffix für lange Doppelliterale?

Was ist das C++-Suffix für lange Doppelliterale?


In C++ (und C) ist ein Fließkommaliteral ohne Suffix standardmäßig double , während das Suffix f impliziert eine float . Aber was ist das Suffix, um einen long double zu erhalten ?


Ohne es zu wissen, würde ich sagen,


const long double x = 3.14159265358979323846264338328;

Aber meine Sorge ist, dass die Variable x enthält weniger signifikante Bits von 3.14159265358979323846264338328 als 64, da dies eine double ist wörtlich. Ist diese Sorge berechtigt?


Antworten:


Aus dem C++-Standard



Interessant ist der Vergleich mit dem entsprechenden Paragraphen der C-Norm. In C wird der Begriff floating constant verwendet statt floating literal in C++:



Einige Code-Antworten


const long double x = 3.14159265358979323846264338328;
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main() { float t1 = 1.10000000000000000002l;
double t2 = 1.10000000000000000002l;
long double t3 = 1.10000000000000000002L;
cout <<
setprecision(25);
cout <<
t1 <<
endl;
cout <<
t2 <<
endl;
cout <<
t3 <<
endl;
}
1.10000002384185791015625 1.100000000000000088817842 1.100000000000000088817842