Safe Haskell | Trustworthy |
---|---|
Language | Haskell2010 |
Primitives to convert between Float/Double and Word32/Word64.
Code copied from binary .
Based on: http://hackage.haskell.org/package/reinterpret-cast-0.1.0/docs/src/Data-ReinterpretCast-Internal-ImplArray.html ..
Implements casting via a 1-element STUArray, as described in http://stackoverflow.com/a/7002812/263061 .
Documentation
wordToFloat :: Word32 -> Float Source #
doubleToWord :: Double -> Word64 Source #
Reinterpret-casts a
Double
to a
Word64
.
\f -> wordToDouble (doubleToWord f ) == f
+++ OK, passed 100 tests.
>>>
showHex (doubleToWord 1.0000000000000004) ""
"3ff0000000000002"
>>>
doubleToWord 1.0000000000000004 == 0x3FF0000000000002
True
>>>
showHex (doubleToWord (-0.15625)) ""
"bfc4000000000000"
>>>
wordToDouble 0xbfc4000000000000
-0.15625