Why does underflow with floating points happen at 2⁻¹²⁶?

Viewed 71

When representing a float, why does the exponent face underflow when it hits 2−126 if 8 bits can hold everything from −127 (incl.) to 128 (incl.)?

2 Answers

Exponents range from −126 to +127 because exponents of −127 (all 0s) and +128 (all 1s) are reserved for special numbers. wikipedia

(considering positive values only, for simplicity...) It has more to do with the 23 bit fraction. Normally, you have 24 (there is an assumed 1 bit, aka "1.fraction") bits of precision. But once the exponent is -127 (it's encoded value is 0, since the exponent is the encoded value - 127), this assumed 1 bit is gone (aka "0.fraction"). So, for subnormals greater or equal to 1/2 x 2^-126, you have only 23 bits of precision. For subnormals less than 1/2 x 2^-126 and greater or equal to 1/4 x 2^-126, you have only 22 bits of precision. Etc.

Related