c++ - 长双字面量的 C++ 后缀是什么?

标签 c++ c literals floating-point-precision

在 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/

相关文章:

c++ - 惯用 std::auto_ptr 还是只使用 shared_ptr?

c# - 在将参数传递给类的构造函数的顺序上是否有任何协议(protocol)或同意?

c++ - *这是什么奇怪的魔法?

c - 如何为这个内联汇编代码编写内联代码?

c - omp ordered 和 omp critical 之间的区别

c++ - MPI_Isend/Recv-是否存在死锁?

c - 如何在 cortex m4 中配置 MPU 寄存器?

javascript - JavaScript中数字文字后的字符 'n'是什么意思?

java - Java 编译器是否将 byte 和 Short 识别为文字?

java - 声明存储在集合中的类型(文字)的变量