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 双


基础教程推荐
- 设计字符串本地化的最佳方法 2022-01-01
- C++ 标准:取消引用 NULL 指针以获取引用? 2021-01-01
- 什么是T&&(双与号)在 C++11 中是什么意思? 2022-11-04
- 您如何将 CreateThread 用于属于类成员的函数? 2021-01-01
- C++ 程序在执行 std::string 分配时总是崩溃 2022-01-01
- 运算符重载的基本规则和习语是什么? 2022-10-31
- 调用std::Package_TASK::Get_Future()时可能出现争用情况 2022-12-17
- C++,'if' 表达式中的变量声明 2021-01-01
- 如何在 C++ 中处理或避免堆栈溢出 2022-01-01
- 如何定义双括号/双迭代器运算符,类似于向量的向量? 2022-01-01