简体   繁体   English

浮点尾数和指数基数 2

[英]Floating-point mantissa and exponent base 2

I'm trying to understand how to get the mantissa and the exponent in this case.我试图了解如何在这种情况下获得尾数和指数。 Here's an example I have in my book.这是我书中的一个例子。

I have this formula (-1)^s * (1 + M) * b^Ee = x我有这个公式(-1)^s * (1 + M) * b^Ee = x

s = 0 or 1 (the sign)
M = mantissa
b = base (In this case 2)
E = the exponent of this mantissa
e = 127 (for a 32bits system)

Still in by book, for x = 1.602177 * 10^-19, I get仍然在书中,对于x = 1.602177 * 10^-19,我得到

S = 0, S = 0,

M = 0.4777474, M = 0.4777474,

E = 64 E = 64

which it works.它有效。

1 * 1.4777474 * 2^-63 = 1.602 10^-19* 1 * 1.4777474 * 2^-63 = 1.602 10^-19*

However, I don't know how to get the values for M and E .但是,我不知道如何获取ME的值。

I read that E = log b |x|我读到E = log b |x| then M = |x|b^-E那么M = |x|b^-E

In this case E = log2(1.602177*10^-19) = -62.43660 (I'm using a website for the log base 2, so I'm not sure about the result so I tried E = -62 and -63).在这种情况下, E = log2(1.602177*10^-19) = -62.43660(我使用的是日志基数 2 的网站,所以我不确定结果,所以我尝试了 E = -62 和 -63) .

M = (1.602177 * 10^-19) * 2^-(-62) = 0.7388737 M = (1.602177 * 10^-19) * 2^-(-62) = 0.7388737

M = (1.602177 * 10^-19) * 2^-(-63) = 1.4777474 M = (1.602177 * 10^-19) * 2^-(-63) = 1.4777474

Correct me if I'm wrong but the mantissa is the digits to the right of the floating point.如果我错了请纠正我,但尾数是浮点数右边的数字。 In this case 0.4777474 looks right.在这种情况下,0.4777474 看起来是正确的。

At this point I have E = -63 and M = 0.4777474, but E should be 64此时我有E = -63 和M = 0.4777474,但E应该是 64

I have E = -63 and M = 0.4777474, but E should be 64我有 E = -63 和 M = 0.4777474,但 E 应该是 64

Mathematically, the exponent is -63 as x = 1.602177 * 10^-19 is in the 2 -63 neighborhood.在数学上,指数为 -63,因为x = 1.602177 * 10^-19在 2 -63邻域内。 Yet the value stored is a 8-bit unsigned biased exponent with binary32 .然而,存储的值是binary32的 8 位无符号偏置指数 Subtract the bias (-127) from the math exponent to get the biased exponent.从数学指数中减去偏差 (-127) 以获得偏差指数。

biased_exponent = expo - bias
64 = -63 - (-127)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM