[Tutor] Associate decimal values with an integer range

eryksun eryksun at gmail.com
Mon Apr 29 23:03:07 CEST 2013


On Mon, Apr 29, 2013 at 12:16 PM, Alan Gauld <alan.gauld at btinternet.com> wrote:
>> I have to interpret a one-byte floating point number
>
> I'm curious, what does a one byte floating point number look like?
> I've never come across such a beast, the smallest FP representation I've
> come across is 16 bits or two bytes. But that wasn't in Python...

For a maximum value of 240.0, an 8-bit floating point (as opposed to
fixed point) format could use 1 sign bit, 4 exponent bits, and 3
significand bits (plus 1 implicit bit). Emax is 7, so the maximum
positive normal would be (2 - 2**-3) * 2**7 == 240.0. Emin is -6, so
the minimum positive normal would be 2**-6. There's approximately 1
decimal digit of precision, i.e. floor(log10(2**4)).

There are 224 normal values in the range [-240.0, 240.0]. Of those, 96
have a magnitude less than 1.0, and 128 have a magnitude in the range
[1.0, 240.0]. There's also +/- zero, +/- infinity, 14 subnormal
values, and 14 NaN (quiet and signaling) values:

      +0: 0 0000 000
      -0: 1 0000 000
    +inf: 0 1111 000
    -inf: 1 1111 000
     sub: x 0000 non-zero
     nan: x 1111 non-zero


More information about the Tutor mailing list