在 C++(和 C)中,没有后缀的浮点字面量默认为 double
,而后缀 f
表示 float
。但是得到 long double
的后缀是什么?
在不知不觉中,我会定义,说,
const long double x = 3.14159265358979323846264338328;
但我担心变量 x
包含的 3.14159265358979323846264338328
的有效位少于 64,因为这是一个 double
文字。这种担心有道理吗?
最佳答案
来自 C++ 标准
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.
与 C 标准的相应段落进行比较很有趣。在 C 中,使用术语 floating constant
而不是 C++ 中的 floating literal
:
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
关于c++ - 长双字面量的 C++ 后缀是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21557816/