[Haskell-cafe] ANN: ieee version 0.7

Daniel Fischer daniel.is.fischer at web.de
Mon Sep 20 06:22:36 EDT 2010

On Monday 20 September 2010 06:47:12, John Millikin wrote:
> On Sun, Sep 19, 2010 at 21:43, Patrick Perry <patperry at gmail.com> wrote:
> >> I needed "real" IEEE754 binary support for round-trip parsing, where
> >> (for example) maintaining the particular bit pattern of a NaN is
> >> important. For 99% of people, the "unsafe" method will work fine.
> >
> > How does a C-style cast not preserve the bit pattern of a NaN?  Again,
> > sorry if this is a stupid question.
> It's not a stupid question, and I don't know the answer. But if you
> plug a C-style cast into the data-binary-ieee754 unit tests, some of
> them (the fiddly ones, like roundtripping -NaN) will fail. Presumably,
> this is due to some optimization deep in the bowels of GHC, but I
> don't understand even a fraction of what goes on in there.
> For what it's worth, d-b-ieee754 was the very first Haskell library I
> ever wrote -- and it shows. If anybody knows how to make unsafeCoerce
> (or equivalent) roundtrip-safe, I would love to rip out all the ugly
> and make it sane.

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):


More information about the Haskell-Cafe mailing list