3 ms·
> And with an exponent bias which isn't part of what anyone learns as basic scientific notation. Luckily, you don't need to understand the exponent bias to und
by cesarb 3y ago
> And with an exponent bias which isn't part of what anyone learns as basic scientific notation.
Luckily, you don't need to understand the exponent bias to understand floating point. All you need to know is that you have for instance 23 bits of mantissa (plus the implicit one), an exponent with range from -126 to +127 (plus the special values -127 and +128), and a sign bit. The exact details of how the exponent is encoded in the 8 bits reserved to it are only important when you're playing tricks with the floating point representation (other than "all zero bits is +0.0", which is often important when zeroing a struct with memset).
- taeric 3y agoThe difficulty, I think, is folks thinking that .2 would be as small of a value as 2? That is, showing the bias in how it goes for the exponent increases is the point. 1e2 is easy for folks to intuit with decimal. As soon as that exponent is to a 2, things get odder. (In particular, I wouldn't be shocked for most peoples intuition that 8 is represented using 100e0 in floats, when I would expect it is 1e11. Right?) Edit: I should say that I realize this isn't the actual exponent bias. I do think this is what would trip up most people, though?
- a_e_k 3y agoYep. And C and C++ now have a hexfloat format that lets you write a float exactly in terms of the mantissa and exponent. For the value `8.0`, you can write it as `0x1p3`. (It's kind of weird in that the unbiased exponent is in decimal while the mantissa is in hex, so `1024.0` could be written `0x1p10`.) The printf/scanf specifier, by the way, is `%a`.
- taeric 3y agoThanks! I was actually surprised at not knowing how to get that representation. In particular, I was surprised that Common Lisp has a way to get binary for integers, but I don't see how to get the float binary printed out. Granted, I don't imagine this comes in necessary that often.