问题
The float format (IEEE) has 32 bits. First bit for the sign, after that 8 bits for a biased exponent and after that another 23 bits for the mantissa. In this mantissa is the first 1 (is always 1) always hidden which leads me to my question:
how does the number 0 look like in this format? because if the exponents 0 the number will always be 1. plus the mantissa is always minimum 1 right? If they are only zeros in the mantissa it will count as '1.0'...
I really don't get this.
回答1:
Wikipedia tells you:
0000 0000 = 0
8000 0000 = −0
Besides the normal float values, with exponent and mantisse there are a bunch of other irregular numbers like zero, infinity and a bunch of NaNs. There are also subnormal numbers; where numbers below 2^-127 are approximated with fixed instead of a floating exponent.
Actually, zero is a normal subnormal number. Subnormals are encoded with as (−1)signbits×2^−126 × 0.significandbits
and exponent all zero. If significantbits is zero, the result is (+/-) zero.
回答2:
IEEE 754 binary floats with the biased exponent zero are not normalized, and there is no implicit one-bit before the binary point in the significand. Zero significand means 0.0 * 2^x, not 1.0 * 2^x.
回答3:
Zero values are represented by the biased exponent and significand both being 0
.
The sign could be 0
or 1
, representing +0.0
and -0.0
respectively.
For example, the negative zero looks like this:
来源:https://stackoverflow.com/questions/26251228/how-does-the-number-0-look-like-in-binary-float-format