长双 vs 双 [英] long double vs double

查看:21
本文介绍了长双 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 双的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆