HN2new | past | comments | ask | show | jobs | submitlogin

It's actually even more complicated...

Remember, this is binary, so the only possible digits are 0 and 1. For example, 1/3 in binary is 0.01010101010101...;

Encoding that in "floating point", we first get:

  1.0101010101 * 2^-2;
We can see that in this format, the first digit of the number is always 1; thus, the first digit of the significand, for any number, is ALWAYS 1 (in binary)! IEEE754 makes the optimization to not store this leading 1 as part of the fraction, so the the approximation to 1/3 is actually encoded as:

  0 01111111101 0101010101010101010101010101010101010101010101010101
  ^      ^            ^
  |      +-----+      |
  sign bit     |    fraction = 1.33333... = 1.01010101010101...0101010101010101b
               |                              |---  this part is included  ---|
               |
        exponent = 01111111101b - 1023 = 1021 - 1023 = -2


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: