[Haskell-cafe] ANN: ieee version 0.7

Conrad Parker conrad at metadecks.org
Tue Sep 21 01:11:24 EDT 2010

On 21 September 2010 12:18, John Millikin <jmillikin at gmail.com> wrote:
> On Mon, Sep 20, 2010 at 03:22, Daniel Fischer <daniel.is.fischer at web.de> wrote:
>> unsafeCoerce is not supposed to work for casts between Integral and
>> Floating types. If you try to unsafeCoerce# between unboxed types, say
>> Double# and Word64#, you're likely to get a compile failure (ghc panic).
>> If you unsafeCoerce between the boxed types, it will probably work, but
>> there are no guarantees.
>> There's a feature request for unboxed coercion (i.e. reinterpretation of
>> the bit-pattern):
>> http://hackage.haskell.org/trac/ghc/ticket/4092
> Interesting -- in that bug report, Simon Mar says that converting the
> value using pointers will work correctly. I've changed d-b-ieee754
> over to use this method (v 0.4.2); the tests are still passing, so
> I'll call it success.

I've been using unsafeCoerce:

getFloat64be :: Get Double
getFloat64be =
    do n <- getWord64be
       return (unsafeCoerce n :: Double)

putFloat64be :: Double -> Put
putFloat64be n = putWord64be (unsafeCoerce n :: Word64)

but only tested it with quickcheck -- it passes about 10^7 checks,
comparing roundtrips in combinatrion with the previous
data-binary-ieee754 versions. However could that sometimes behave

Should the d-b-iee754-0.4.2 versions with castPtr etc. be even faster?


More information about the Haskell-Cafe mailing list