长双 vs 双

long double vs double(长双 vs 双)
本文介绍了长双 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 双的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Rising edge interrupt triggering multiple times on STM32 Nucleo(在STM32 Nucleo上多次触发上升沿中断)
How to use va_list correctly in a sequence of wrapper functions calls?(如何在一系列包装函数调用中正确使用 va_list?)
OpenGL Perspective Projection Clipping Polygon with Vertex Outside Frustum = Wrong texture mapping?(OpenGL透视投影裁剪多边形,顶点在视锥外=错误的纹理映射?)
How does one properly deserialize a byte array back into an object in C++?(如何正确地将字节数组反序列化回 C++ 中的对象?)
What free tiniest flash file system could you advice for embedded system?(您可以为嵌入式系统推荐什么免费的最小闪存文件系统?)
Volatile member variables vs. volatile object?(易失性成员变量与易失性对象?)