IEEE 754浮点表示是否浪费内存? [英] Is IEEE 754 floating point representation wasting memory?

查看:155
本文介绍了IEEE 754浮点表示是否浪费内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我始终认为有2 ^ 64个不同的小数值可以被double类型的变量存储。 (每一位可以有1或0作为值,所以有2 ^ 64个不同的值)。

最近我才知道NaN(不是数字)有一个表示其中指数部分为11111111111,有效部分为非零值。
如果指数部分是11111111111,有效部分是111111 ......(52次),那么它的表示形式就是NaN。

这难道不会让我们代表2 ^ 52个更多不同的数字吗? 2 ^ 52是一个很大的数字。那么我们是不是在浪费宝贵的空间?

解决方案

IEEE-754浮点格式的设计考虑到了高效的硬件实现。所有特殊输入操作数都可以通过检查指数字段来检测,它可以是全部 0 (零和非正则表达式)或全部 1 (infinities和NaNs)。所以对于双精度来说,只需要一个11位的比较器,检查可以在一个处理器周期的一小部分内执行。

保留2048个可能的指数无限编码和NaN并不特别浪费。请注意,IEEE-754使用两种不同类型的NaN:信号NaN或SNaN在遇到时会触发异常,而相当的NaN或QNaNs只是通过计算传播,直到出现在人为消耗的最终结果中。尾数字段的最重要的位在两种NaN之间进行区分:它被清除为SNaNs,并被设置为QNaNs。

另外,IEEE-754支持但不要求NaN有效载荷的概念,即多个NaN编码与系统或用户定义的含义。例如,PowerPC Numerics(Apple 1994)为Macintosh系统指定了NaN的分数字段的第8至第15最高有效位包含NaN码,该NaN码指示NaN的不同来源,例如,负数之外的负数的 sqrt(),负数的 log()三角函数,如 asin()。这个概念已经被Apple II引入的SANE(标准Apple数值环境)所使用,如Apple Numerics Manual,Second Edition(Apple 1988)中所描述的。

C和C ++标准通过 math.h / 提供了一个标准函数 nan() cmath 可以用来以实现定义的方式从字符串参数构造NaN有效载荷。有关简要说明,请参阅此处


I always thought that there are 2^64 different fractional values that can be stored by a variable of type double. (Each bit can have either 1 or 0 as value and so 2^64 different values).

Recently I came to know that NaN (not a number) has a representation in which exponent part is 11111111111 and significand part is any non-zero value. Instead, if it were like the representation is NaN if exponent part is 11111111111 and significand part is 111111......(52 times) ?

Won't this allow us to represent 2^52 more different numbers? And 2^52 is a huge number. So are we not wasting the valuable space?

解决方案

The IEEE-754 floating-point formats were designed with efficient hardware implementation in mind. All the special input operands can be detected by examining the exponent field only, which is either all-0 (zeros and denormals), or all-1 (infinities and NaNs). So for double precision specifically, only a 11-bit comparator is required, and the check can be performed in a fraction of a processor cycle.

Reserving one of 2048 possible exponent encodings for infinities and NaNs is not particularly wasteful. Note that IEEE-754 uses two different kind of NaNs: Signalling NaNs, or SNaNs, trigger an exception when encountered, while quite NaNs, or QNaNs, are simply propagated through computation until they appear in human-consumable final results. The most significant bit of the mantissa field distinguishes between the two kinds of NaNs: it is cleared for SNaNs and set for QNaNs.

Additionally, IEEE-754 supports, but does not require, the concept of NaN "payload", i.e. multiple NaN encodings with system- or user-defined meanings. For example, "PowerPC Numerics" (Apple 1994), specifies for the Macintosh system that the 8th through 15th most significant bits of the fraction field of a NaN contain a NaN code which indicates the different origins of NaNs, e.g. sqrt() of a negative number other than zero, log() of a negative number, invalid argument to an inverse trigonometric functions such as asin(). The concept was already used by the SANE (Standard Apple Numerical Environment) introduced with the Apple II, as described in "Apple Numerics Manual, Second Edition" (Apple 1988).

The C and C++ standards provide a standard function nan() via math.h / cmath that can be used to construct NaN payloads from a string argument in an implementation-defined manner. For a brief description see for example here.

这篇关于IEEE 754浮点表示是否浪费内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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