C和C ++中long double和double之间的区别 [英] Difference between long double and double in C and C++

查看:459
本文介绍了C和C ++中long double和double之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

long double vs double

我是编程新手,无法理解C和C ++中long double和double之间的区别。我尝试使用Google,但无法理解它并感到困惑。有人可以帮忙吗??

I am new to programming and I am unable to understand the difference between between long double and double in C and C++. I tried to Google it but was unable to understand it and got confused. Can anyone please help.?

推荐答案

引用C ++标准的§3.9.1¶8:

To quote the C++ standard, §3.9.1 ¶8:


有三种浮点类型:float,double和long double。 double类型至少提供与float一样的精度,long long类型提供至少与double一样高的精度。 float类型的值集是double类型的值集的子集; double类型的值集是long double类型的值集的子集。浮点类型的值表示形式是实现定义的。整数和浮点类型统称为算术类型。标准模板std :: numeric_limits(18.3)的专业化应指定实现的每种算术类型的最大值和最小值。

There are three floating point types: float, double, and long double. The type double provides at least as much precision as float, and the type long double provides at least as much precision as double. The set of values of the type float is a subset of the set of values of the type double; the set of values of the type double is a subset of the set of values of the type long double. The value representation of floating-point types is implementation-defined. Integral and floating types are collectively called arithmetic types. Specializations of the standard template std::numeric_limits (18.3) shall specify the maximum and minimum values of each arithmetic type for an implementation.

也就是说, double 至少要花与 float 相同的内存。 long double 至少与 double 一样多。额外的内存用于更精确地表示数字。

That is to say that double takes at least as much memory for its representation as float and long double at least as much as double. That extra memory is used for more precise representation of a number.

在x86系统上, float 通常为4个字节长,可以存储大约3×10³⁸和小的1.4×10⁻⁴⁵的数字。这是一个IEEE 754 单精度数字,它存储约7个小数的小数位。

On x86 systems, float is typically 4 bytes long and can store numbers as large as about 3×10³⁸ and about as small as 1.4×10⁻⁴⁵. It is an IEEE 754 single-precision number that stores about 7 decimal digits of a fractional number.

在x86系统上, double 的长度为8个字节,可以在IEEE 754中存储数字双精度格式,范围更大,并且存储的数字精度更高,大约为15个十进制数字。在某些其他平台上, double 的长度可能不为8个字节,并且实际上与单精度 float 相同。 。

Also on x86 systems, double is 8 bytes long and can store numbers in the IEEE 754 double-precision format, which has a much larger range and stores numbers with more precision, about 15 decimal digits. On some other platforms, double may not be 8 bytes long and may indeed be the same as a single-precision float.

标准只要求 long double 至少与 double <一样精确。 / code>,因此某些编译器将把 long double 视为与 double 相同。但是,在大多数x86芯片上,可通过CPU的浮点数获​​得10字节的扩展精度格式 80位数字点单元,它的精度比64位 double 还要高,精度约为21位十进制数字。

The standard only requires that long double is at least as precise as double, so some compilers will simply treat long double as if it is the same as double. But, on most x86 chips, the 10-byte extended precision format 80-bit number is available through the CPU's floating-point unit, which provides even more precision than 64-bit double, with about 21 decimal digits of precision.

某些编译器改为支持16字节(128位)IEEE 754 四倍精度数字格式更精确的表示形式和更大的范围。

Some compilers instead support a 16-byte (128-bit) IEEE 754 quadruple precision number format with yet more precise representations and a larger range.

这篇关于C和C ++中long double和double之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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