[Haskell-cafe] Why aren't Float and Double Bounded?

Bit Connor bit at mutantlemon.com
Tue Nov 27 15:54:47 EST 2007

> Actually, IEEE numbers are designed in such a way, that if you interpret
> their bits as integer number, then 'succ' leads you to the next larger
> representable number. Thus you only have to cast from Float or Double to
> Int32 or Int64 respectively, call enumFromTo, then cast back to Float or
> Double, respectively. :-]

How do you cast from Float to Int32(or Word32), and back again? I
couldn't find an appropriate function. Only thing I can see is going
through the Storable interface, but that seems cumbersome and I
imagine slow.

Also, a related question: How do you convert from Float -> Double, and
the reverse? Only thing I could find is (fromRational . toRational)
which I also imagine to be slow, and I also wonder about accuracy.


More information about the Haskell-Cafe mailing list