为什么无限的浮点表示显然是0 ^ n? [英] Why is infinity's floating point representation apparently 0^n?

查看:226
本文介绍了为什么无限的浮点表示显然是0 ^ n?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解浮点表示。我不明白浮点无穷大的NaN表示。
我正在查看 TopCoder提供的表格

Infinity由全1的指数和所有0的尾数表示。

I只能读为0 ^ n,我不知道如何趋于无穷。

解决方案

你应该忽略所使用的位模式,并将无穷和无限小数视为特殊值。除非你在浮游物上做些小小的摆弄(对此我没有什么理由要这样做),否则只有在IEEE规则说应该创建的地方才会遇到这些值,而忽略了这个问题是安全的。计算机如何代表他们。即使你做的不是标准的计算,我的猜测是99%的时间,位模式并不重要。

当然,以上都不是说你应该忽略标准的,有限的,非零浮点数的实现。尽管从尾数/指数到记忆中的位的步骤仍然几乎不相关。在你链接的页面中,作者声称C ++中的全局变量被初始化为零位模式 - 这是错误的。在C ++中,POD类型的全局变量被初始化为语义零所需的任何位模式(§3.6.2.2,§8.5.5)。我相信C ++标准并不要求任何特定的位模式用于任何浮点值。


I am trying to understand floating point representations. I do not understand the 'infinity' 'NaN' representations in floating point. I am looking at the table provided by TopCoder.

Infinity is represented by an exponent of all 1s and a Mantissa of all 0s.

I can only read it as 0^n, and I'm not sure how that tends to infinity.

解决方案

You should simply ignore the bit patterns used and treat infinities and NaNs as special values. Unless you do bit-fiddling on your floats (for which I see very little reason to do), you will only encounter these values in the places where the IEEE rules say they should be created, and it will be safe to ignore the question of how the computer represents them. Even if you do more than standard calculations, my guesstimate is that 99% of the time, the bit patterns just don't matter.

Of course, none of the above says you should ignore the implementation of standard, finite, non-zero floating point numbers. Although the step from mantissa/exponent to bits in memory is still hardly ever relevant. In the page you linked to, the author claims that "global variables in C++ are initialized to a zero bit pattern" – that is wrong. Global variables of POD type in C++ are initialized with whatever bit pattern is needed for a semantic zero (§3.6.2.2, §8.5.5). I believe the C++ standard does not require any particular bit pattern for any floating-point value.

这篇关于为什么无限的浮点表示显然是0 ^ n?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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