when i am looking at the wikipedia page for Offset Binary, i cant follow the following sentence:
Unusually however, instead of using “excess 2^(n-1)” it uses “excess
2^(n-1)-1” which means that inverting the leading (high-order) bit of
the exponent will not convert the exponent to correct twos’ complement
notation.
can anyone explain it in details and give me some examples?
This is the range of exponents which allows you to calculate 1/Float.MAX_VALUE and 1/Float.MIN_NORMAL without going to zero or Infinity. If there was one more negative exponent and one less positive exponent, (with an offset of 128) 1/Float.MIN_NORMAL would be Infinity.
The exponent in floating point is offset rather than plain two-complement.
e.g. for
doublea 0 exponent is 11-bit value for 1023 or 0b0111111111, -1 is 1022 or 0b0111111110, +1 is 1024 0b10000000000.In twos-complement, the number would be 0 is 0b00000000000, -1 is 0b11111111111, and +1 is 0b00000000001
A property of using an offset, is that the maximum is half the possible number of values. i.e. for 11 bits the range is -1023 to 1024 instead of -1024 to 1023.
Another property is that number can be compared by just comparing the integer values.
i.e.
The only difference is in the handling of NaN and -0.0 The approach Double.compare(double, double) uses is based on this.