ivory- Safe embedded C programming.

Safe HaskellNone



Safe casting. We assume Floats have 32 bits and Doubles have 64.



ivoryCast :: forall a b. (IvoryExpr a, IvoryExpr b) => a -> bSource

castWith :: RuntimeCast from to => to -> from -> toSource

Cast with a default value if the casted value is too large.

castDefault :: (Default to, RuntimeCast from to) => from -> toSource

`CastWith 0` for types for which 0 is defined.

class (IvoryExpr from, IvoryExpr to) => SafeCast from to whereSource

Statically safe casts.


safeCast :: from -> toSource

class (IvoryExpr from, IvoryExpr to, Default to) => RuntimeCast from to Source

Casts requiring runtime checks.


(Bounded from, Bounded to, IvoryOrd from, IvoryOrd to, IvoryExpr from, IvoryExpr to, Default from, Default to, SafeCast to from) => RuntimeCast from to 
(Default to, Bounded to, IvoryIntegral to, SafeCast to IDouble) => RuntimeCast IDouble to 
(Default to, Bounded to, IvoryIntegral to, SafeCast to IFloat) => RuntimeCast IFloat to

Casting from a floating to a Integral type always results in truncation.

class (IvoryExpr from, IvoryExpr to) => SignCast from to whereSource

SignCast takes a unsigned number into its signed form iff safe, otherwise 0, and same with signed into unsigned


signCast :: from -> toSource