long double vs double(长双 vs 双)
问题描述
我知道各种数据类型的大小可能会根据我所在的系统而变化.
I know that size of various data types can change depending on which system I am on.
我使用 XP 32bits,并在 C++ 中使用 sizeof() 运算符,似乎 long double 是 12 个字节,而 double是 8.
I use XP 32bits, and using the sizeof() operator in C++, it seems like long double is 12 bytes, and double is 8.
然而,大多数主要资料表明 long double 是 8 个字节,因此范围与 double 相同.
However, most major sources states that long double is 8 bytes, and the range is therefore the same as a double.
我怎么有 12 个字节?如果 long double 确实是 12 个字节,这不是也扩展了值的范围吗?或者长签名仅在值超出双精度范围时使用(编译器数字),因此超出 8 个字节?
How come I have 12 bytes? If long double is indeed 12 bytes, doesn't this extends the range of value also? Or the long signature is only used (the compiler figures) when the value exceed the range of a double, and thus, extends beyond 8 bytes?
推荐答案
引用 维基百科:
在 x86 架构上,大多数编译器将 long double 实现为该硬件支持的 80 位扩展精度类型(有时存储为 12 或 16 字节以维护数据结构.
On the x86 architecture, most compilers implement long double as the 80-bit extended precision type supported by that hardware (sometimes stored as 12 or 16 bytes to maintain data structure .
和
编译器还可以将 long double 用于 128 位四倍精度格式,目前在软件中实现.
Compilers may also use long double for a 128-bit quadruple precision format, which is currently implemented in software.
换句话说,是的,long double 可能能够存储比 double 更大范围的值.但这完全取决于编译器.
In other words, yes, a long double may be able to store a larger range of values than a double. But it's completely up to the compiler.
这篇关于长双 vs 双的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:长双 vs 双
基础教程推荐
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- CString 到 char* 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
