Search code examples
floating-pointrangemedian

16-bit floating point range and median


We have a floating-point code that fit in 16 bits, with 1 bit for the sign and 4 bits for the exponent and 11 bits for the significant. I've read about floating points and was able to find the range of normalized exponent. I think it would be 1-bias and 2^(exp-1) - 1 which leads to a range of [-6,7].

I've also been trying to find the range of positive denormalized values, the median value of the code, the, the median of the positive normalized values and the median of the positive values.

I know for finding the largest positive normalized value, I need to calculate 0 0000 11111111111 (smallest) and 0 1110 11111111111 (largest). Also, how many different values are able to be encoded? Would it be 2^16?


Solution

  • The following only makes sense if you use an ieee-754-like format, which is reasonable as you appear to be following that standard for determining your largest number above. I have taken your implied questions quite literally, I hope it is useful.

    Range of denormalised values

    0 0000 00000000000 - 0 0000 11111111111
    

    That's 0 to 2^-6 * (1-2^-11)

    Median value of the code

    Medians are just the 'middle' of all of the codes. If you order everything by code, these are the two central ones:

    0 1111 11111111111
    1 0000 00000000000
    

    That's between NaN and minus zero! If you want to interpolate a value between zero and NaN you answer will be NaN. It may make more sense to say that 0.0 is the central code in the normal order of floating point numbers if you just order them by value.

    The median of the positive normalized values

    We need to find the middle of the range the range:

    0 0001 00000000000
    0 1110 11111111111
    

    Add the non-counted codes, divide the code by two. That's between.

    0 0111 11111111111
    0 1000 00000000000
    

    That's about 2.0.

    Median of the positive values.

    Similar logic, get to: 0 0111 01111111111

    That's about 1.5. (It makes sense that including an extra range of mantissa bits, nudges your median by half a mantissa range)

    Number of different values that can be encoded

    That's 2^16 if you distinguish different NaNs and -0.

    If you exclude NaNs you must subtract, for each of the signs, all the NaN representing codes (all nonzero mantissas): 2^16-2*(2^11-1).