[DGD] Perfect dump of float

Shentino shentino at gmail.com
Sat May 28 08:54:54 CEST 2011


My original plan included using frexp to split the exponent and mantissa,
then do a series of "shifts" (multiply by power of two) to extract all the
bits.

On Fri, May 27, 2011 at 10:51 PM, Jared Maddox <absinthdraco at gmail.com>wrote:

> On Sat, May 28, 2011 at 12:22 AM, Jared Maddox <absinthdraco at gmail.com>
> wrote:
> >> Date: Thu, 26 May 2011 23:42:21 -0700
> >> From: Shentino <shentino at gmail.com>
> >> To: "All about Dworkin's Game Driver" <dgd at dworkin.nl>
> >> Subject: [DGD] Perfect dump of float
> >> Message-ID: <BANLkTimm1C6VE=3mTQXgGG1zPvo3wcjtsg at mail.gmail.com>
> >> Content-Type: text/plain; charset=UTF-8
> >>
> >> Since it's not possible to access the raw bit pattern, I was curious.how
> one
> >> might dump a perfect representation of a float that doesn't result in
> even
> >> one bit of data to be lost.
> >>
> >> My guess is that one would need to do some sort of ldexp to split the
> >> mantissa and exponent apart, then use float.h for information on how
> many
> >> fraction bits to extract from the mantissa for dumping out as hex.
> >
> > My advice is to divide it into two pieces (mantissa and exponent will
> > work), convert both to integers (example: if your mantissa is an 8 bit
> > unsigned fraction, then your integer is 255 * mantissa, if signed then
> > 127 * mantissa), and use the integers. I originally came up with this
> > for streaming floats over networks; due to it's purely-mathematical
> > basis, it should work for every language with a function that splits
> > floats into purely-integer and/or purely-fractional parts.
> >
>
> Oops, math mistake. Unless your 'fractional bits' can be equal to 1.0,
> the correct values for 8-bit precision would be 256 for unsigned and
> 128 for signed, otherwise you'd get slightly LESS than 8-bit
> precision.
> ___________________________________________
> https://mail.dworkin.nl/mailman/listinfo/dgd
>



More information about the DGD mailing list