[DGD] DGD Digest, Vol 58, Issue 9
Jared Maddox
absinthdraco at gmail.com
Sat May 28 07:22:35 CEST 2011
> 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.
More information about the DGD
mailing list