What's the C++ suffix for long double literals?
In C++ (and C), a floating point literal without suffix defaults to double
, while the suffix f
implies a float
. But what is the suffix to get a long double
?
Without knowing, I would define, say,
const long double x = 3.14159265358979323846264338328;
But my worry is that the variable x
contains fewer significant bits of 3.14159265358979323846264338328
than 64, because this is a double
literal. Is this worry justified?
From the C++ Standard
The type of a floating literal is double unless explicitly specified by a suffix. The suffixes f and F specify float, the suffixes l and L specify long double.
It is interesting to compare with corresponding paragraph of the C Standard. In C there is used term floating constant
instead of floating literal
in C++:
4 An unsuffixed floating constant has type double. If suffixed by the letter f or F, it has type float. If suffixed by the letter l or L, it has type long double
The C suffix is L
. I'd strongly suspect that it is the same for C++.
Your worry is justified. Your literal would first be converted to a double
, and thus truncated, and then converted back to long double
.