Why is infinity's floating point representation apparently 0^n?

空扰寡人 提交于 2019-12-25 04:04:52

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/10528730/why-is-infinitys-floating-point-representation-apparently-0n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!