Why is it that the IEEE 754 standard provide 8 bits for the exponent but puts a range maximum of 38 on the largest acceptable exponent?
Seems kind of ridiculous to have the data storage there but not allow it to actually be used.
I wanted to pack data into this exponent for some encoding I’m doing, but I can’t use all the bits because I can’t pack an exponent larger than 38! I was hoping to pack values up to 256 using all bits (2 ^ 8).
0
Floating point stores the exponent and mantissa in base two, not base 10. Two to the 127th power corresponds roughly to ten to the 38th power, so that’s the largest decimal number that can be stored.
See https://www.google.com/#q=2+to+the+127th+power
1
IEEE 754 standard single-precision (i.e., 32-bit) floats reserve 1 bit for the sign bit, 8 for the exponent, and 23 for the mantissa. I’m not sure where you’re getting a value of 38 (base 10) from as the “maximum” exponent. Please clarify in the comments if I’m interpreting this incorrectly.
Since the exponent is 8 bits, the range of exponent values can be anywhere between 00000000 and 11111111 (which are reserved for 0 and infinity, respectively). However, any exponent value between 00000001 and 11111110 is valid. So, accounting for a bias of -127, you can achieve an exponent of 127.
So, assuming a mantissa of all 1’s (i.e., a value very close to 2), you can achieve up to 2^127 for your encoding.
If all you need is 2^8 for your encoding, consider using overall fewer bits in your floating point number.
Read more here: http://steve.hollasch.net/cgindex/coding/ieeefloat.html
1