[英]Where's the 24th fraction bit on a single precision float? IEEE 754
I found myself today doing some bit manipulation and I decided to refresh my floating-point knowledge a little! 我发现自己今天做了一些操作,我决定稍微刷新我的浮点知识!
Things were going great until I saw this: 事情都很顺利,直到我看到了这一点:
... 23 fraction bits of the significand appear in the memory format but the total precision is 24 bits
...有效数的23个小数位出现在存储器格式中,但总精度为24位
I read it again and again but I still can't figure out where the 24th bit is, I noticed something about a binary point
so I assumed that it's a point in the middle between the mantissa
and the exponent
. 我一次又一次地阅读它,但我仍然无法弄清楚第24位的位置,我注意到有关
binary point
所以我认为它是mantissa
和exponent
之间的中间点。
I'm not really sure but I believe he author was talking about this bit: 我不太确定,但我相信他的作者正在谈论这一点:
Binary point?
|
s------e-----|-------------m----------
0 - 01111100 - 01000000000000000000000
^ this
The 24 th bit is implicit due to normalization. 第 24位是由于归一化隐式的。
The significand is shifted left (and one subtracted from the exponent for each bit shift) until the leading bit of the significand is a 1. 有效数向左移位(并且每个位移从指数中减去一个)直到有效数的前导位为1。
Then, since the leading bit is a 1, only the other 23 bits are actually stored. 然后,由于前导位是1,所以实际上只存储了其他23位。
There is also the possibility of a denormal number. 还有可能存在非正规数。 The exponent is stored as a "bias" format signed number, meaning that it's an unsigned number where the middle of the range is defined to mean
0
1 . 指数存储为“偏差”格式有符号数,这意味着它是无符号数,其中范围的中间定义为
0
1 。 So, with 8 bits, it's stored as a number from 0..255, but 0 is interpreted to mean -128, 128 is interpreted to mean 0, and 255 is interpreted as 127 (I may have a fencepost error there, but you get the idea). 因此,对于8位,它存储为0..255的数字,但0被解释为-128,128被解释为0,而255被解释为127(我可能有一个fencepost错误,但是你得到这个想法)。
If, in the process of normalization, this is decremented to 0 (meaning an actual exponent value of -128), then normalization stops, and the significand is stored as-is. 如果在归一化过程中,它递减到0(意味着实际指数值为-128),则归一化停止,并且有效数据按原样存储。 In this case, the implicit bit from normalization it taken to be a 0 instead of a 1.
在这种情况下,从归一化的隐含位取为0而不是1。
Most floating point hardware is designed to basically assume numbers will be normalized, so they assume that implicit bit is a 1. During the computation, they check for the possibility of a denormal number, and in that case they do roughly the equivalent of throwing an exception, and re-start the calculation with that taken into account. 大多数浮点硬件被设计成基本上假设数字将被规范化,因此它们假设隐含位是1.在计算期间,它们检查非正规数的可能性,并且在这种情况下它们大致相当于抛出异常,并重新开始计算。 This is why computation with denormals often gets drastically slower than otherwise .
这就是为什么使用非正规数计算通常会比其他情况慢得多的原因 。
Normally (pardon the pun), the leading bit of a floating point number is always 1; 通常(原谅双关语),浮点数的前导位始终为1; thus, it doesn't need to be stored anywhere.
因此,它不需要存储在任何地方。 The reason is that, if it weren't 1, that would mean you had chosen the wrong exponent to represent it;
原因是,如果它不是1,那就意味着你选择了错误的指数代表它; you could get more precision by shifting the mantissa bits left and using a smaller exponent.
你可以通过将尾数位向左移动并使用较小的指数来获得更高的精度。
The one exception is denormal/subnormal numbers, which are represented by all zero bits in the exponent field (the lowest possible exponent). 一个例外是非正规/次正规数,它们由指数字段中的所有零位(最低可能指数)表示。 In this case, there is no implicit leading 1 in the mantissa, and you have diminishing precision as the value approaches zero.
在这种情况下,尾数中没有隐式前导1,并且当值接近零时,精度会降低。
For normal floating point numbers, the number stored in the floating point variable is (ignoring sign) 1. mantissa * 2
exponent-offset
. 对于正常浮点数,存储在浮点变量中的数字是(忽略符号)
1. mantissa * 2
exponent-offset
。 The leading 1 is not stored in the variable. 前导1不存储在变量中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.