长双双 [英] long double vs double

查看:116
本文介绍了长双双的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道各种数据类型的大小可以根据我所在的系统而改变。
我使用XP 32位,并在C ++中使用sizeof()运算符,似乎long double是12字节,double是8。

I know that size of various data types can change depending on which system I am on. 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个字节,那么这个值的范围是否也扩展了呢?或者只有当值超过double的范围时才使用长签名(编译器数字),因此扩展到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?

谢谢。 p>

Thank you.

推荐答案

引用自维基百科


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


编译器也可以对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.

这篇关于长双双的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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