ivory-0.1.0.0: Safe embedded C programming.

Safe HaskellNone

Ivory.Language.Cast

Description

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

Synopsis

Documentation

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.

Methods

safeCast :: from -> toSource

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

Casts requiring runtime checks.

Instances

(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

Methods

signCast :: from -> toSource