plutus-core-1.54.0.0: Language library for Plutus Core
Safe HaskellTrustworthy
LanguageHaskell2010

PlutusCore.Flat.Data.FloatCast

Description

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.

Synopsis

Documentation

floatToWordFloatWord32 Source #

Reinterpret-casts a Float to a Word32.

wordToFloatWord32Float Source #

Reinterpret-casts a Word32 to a Float.

\f -> wordToFloat (floatToWord f ) == f

+++ OK, passed 100 tests.

>>> floatToWord (-0.15625)
3189768192
>>> wordToFloat 3189768192
-0.15625
>>> floatToWord (-5.828125) == 0xC0BA8000
True

doubleToWordDoubleWord64 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

wordToDoubleWord64Double Source #

Reinterpret-casts a Word64 to a Double.

runST ∷ (∀ s. ST s a) → a Source #

Return the value computed by a state thread. The forall ensures that the internal state used by the ST computation is inaccessible to the rest of the program.

cast ∷ (MArray (STUArray s) a (ST s), MArray (STUArray s) b (ST s)) ⇒ a → ST s b Source #

>>> runST (cast (0xF0F1F2F3F4F5F6F7::Word64)) == (0xF0F1F2F3F4F5F6F7::Word64)
True