On 29 April 2013 22:03, eryksun <[email protected]> wrote: > On Mon, Apr 29, 2013 at 12:16 PM, Alan Gauld <[email protected]> > 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
Brilliant. I thought you were just making this up but here http://mrob.com/pub/math/floatformats.html I find that 8 bit floating point with values up to 240 is listed as a floating point format. The link describes it as "Used in university courses" so I guess it's not intended to be a practical format. Oscar _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
