本文介绍了inf和NaN的内部表示是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友&我正在辩论今天午餐时如何储存Inf和NaN。



以Fortran 90为例。 4字节的实数可以获得Inf或NaN的值。这是如何存储在内部的?据推测,一个4字节的实数是由一个32位二进制数字内部表示的数字。 Inf和NaN是以33位二进制数存储的吗?

pbs.edu/general/software/packages/ieee/ieee.phprel =noreferrer> link :

IEEE单精度浮点标准表示需要一个32位字,它可以表示为从0到31的编号,从左到右。第一位是符号位, S ,接下来的八位是指数位,' E ',最后的23位是小数点' F ':

 
EEEEEEEE FFFFFFFFFFFFFFFFFFFFFFF
0 1 8 9 31

由该词表示的 V 可以如下确定:


  • 如果 E = 255 F 非零,则 V = NaN (不是数字)

  • code> E = 255 和 F 为零且 S 1 ,然后 V = -Infinity

  • 如果 E = 255 F 为零且 S 0 ,则 V = Infinity

  • 如果 0 然后 V =( - 1)** S * 2 **(E-127)*(1.F)其中 1.F 旨在表示通过用隐式前导1和二进制前缀F创建的二进制数
    点。如果 E = 0 F 不为零,则 V =( - 1)** S * 2 **(-126)*(0.F)这些
    是非标准化值。

  • 如果 E = 0 F 为零且 S 1 ,然后 V = -0

  • 如果 E = 0 F 为零且 S 0 ,然后 V = 0


A friend & I were debating how Inf's and NaN's are stored during lunch today.

Take Fortran 90 for example. 4-byte reals can obtain the value of Inf or NaN. How is this stored internally? Presumably, a 4-byte real is a number represented internally by a 32 digit binary number. Are Inf's and NaN's stored as 33 bit binary numbers?

解决方案

Specifically from Pesto's link:

The IEEE single precision floating point standard representation requires a 32 bit word, which may be represented as numbered from 0 to 31, left to right. The first bit is the sign bit, S, the next eight bits are the exponent bits, 'E', and the final 23 bits are the fraction 'F':

S EEEEEEEE FFFFFFFFFFFFFFFFFFFFFFF
0 1      8 9                    31

The value V represented by the word may be determined as follows:

  • If E=255 and F is nonzero, then V=NaN ("Not a number")
  • If E=255 and F is zero and S is 1, then V=-Infinity
  • If E=255 and F is zero and S is 0, then V=Infinity
  • If 0<E<255 then V=(-1)**S * 2 ** (E-127) * (1.F) where "1.F" is intended to represent the binary number created by prefixing F with an implicit leading 1 and a binarypoint.
  • If E=0 and F is nonzero, then V=(-1)**S * 2 ** (-126) * (0.F) Theseare "unnormalized" values.
  • If E=0 and F is zero and S is 1, then V=-0
  • If E=0 and F is zero and S is 0, then V=0

这篇关于inf和NaN的内部表示是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 15:29