Float compression [Re: floating point math results question]

François Pinard pinard at iro.umontreal.ca
Sat Jan 26 16:07:49 EST 2002


[Peter Hansen]
> [Phil Hunt]
> > [Courageous]

> > >Second, as an academic exercise, you may now attempt to represent the
> > >number 0.8 [that is: 4.0/5.0] ]as a 32 bit binary value.

> > I can do it in 24 binary bits: 00110000 00101110 00111000

> Naw, that was 26 ASCII characters.  The original "0.8" is 24 bits.
> I can do it in 16 bits: ".8" !!  Fewer if you are willing to drop the
> leading binary zeros.  <grin>

I guess that it is an interesting exercise, trying to represent an arbitrary
float number within a given tolerance, with a small number of bits.

Let's take math.pi, say.  It can be represented by 355:113 if the tolerance
is over 0.00000027.  Maybe we could find efficient binary representations
for 355 followed by 113, and this probably turns out into finding efficient
ways for coding the bit length of each.

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard




More information about the Python-list mailing list