[Haskell-cafe] question about Data.Binary and Double instance
Brian Alliet
brian at brianweb.net
Tue Apr 17 23:42:40 EDT 2007
On Wed, Apr 18, 2007 at 12:34:58PM +1000, Duncan Coutts wrote:
> We'd like to use IEEE format as the default Data.Binary serialisation
> format for Haskell's Float and Double type, the only thing that makes
> this tricky is doing it portably and efficiently.
You should note that your current method of serializing Doubles
(encodeFloat/decodeFloat) isn't portable either as the results of these
functions depend on floatRadix. So using some method that depends on
IEEE representation isn't much worse (might actually be better as you'd
get an error at runtime rather than writing data that could potentially
be read back as garbage).
I think the only way to do this 100% portably is to encode it as a
Rational before serializing.
Also even if someone were to bother to write the code to convert from
an arbitrary floating point rep to IEEE for serialization you'd run the
risk losing information if the hosts floating point rep was more
accurate that IEEE FP.
It seems like it might come down to making a choice between 100%
portable but incompatable with the default serialization mechanisms in
other languages or non-portable (but ok for just about every popular
arch used today) and compatable with other languages.
> Perhaps we just don't care about ARM or other arches where GHC runs that
Are there really any architectures supported by GHC that don't use IEEE
floating point? If so GHC.Float is wrong as isIEEE is always true.
-Brian
More information about the Haskell-Cafe
mailing list