Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Extend floating point types with a larger exponent range.
Synopsis
- class RealFloat a => ExpExtendable a where
- data ExpExtended a
- withExpExtended :: ExpExtended a -> (a -> Int -> r) -> r
- unsafeExpExtended :: a -> Int -> ExpExtended a
- cache :: Cache a
- expExtended :: a -> Int -> ExpExtended a
- expExtended' :: ExpExtendable a => a -> ExpExtended a
- unExpExtendable :: ExpExtendable a => ExpExtended a -> Bool
- unExpExtended :: ExpExtendable a => ExpExtended a -> a
- type EDouble = ExpExtended Double
- type EFloat = ExpExtended Float
Documentation
class RealFloat a => ExpExtendable a where Source #
Extend floating point types with a larger exponent range.
Implementors need only implement:
- the
ExpExtended
data type, isomorphic to a strict pair(a,
Int
) - its constructor
unsafeExpExtended
- its destructor
withExpExtended
Using a data family allows the UNPACK optimisation.
data ExpExtended a Source #
withExpExtended :: ExpExtended a -> (a -> Int -> r) -> r Source #
Deconstruct into basic value and exponent.
unsafeExpExtended :: a -> Int -> ExpExtended a Source #
Construct from a basic value and an exponent, without checking the
invariant. Use expExtended
instead.
Cache of magic values. Stored once per instance to avoid recomputation.
expExtended :: a -> Int -> ExpExtended a Source #
Construct from a basic value and an exponent, ensuring that the result establishes the internal invariant:
m == significand m && ((m == 0 || isInfinite m || isNaN m) ==> e == 0)
Also handles overflow to infinity, and underflow to zero.
Instances
ExpExtendable Double Source # | |
Defined in Numeric.ExpExtended data ExpExtended Double :: Type Source # withExpExtended :: ExpExtended Double -> (Double -> Int -> r) -> r Source # unsafeExpExtended :: Double -> Int -> ExpExtended Double Source # cache :: Cache Double Source # expExtended :: Double -> Int -> ExpExtended Double Source # | |
ExpExtendable Float Source # | |
Defined in Numeric.ExpExtended data ExpExtended Float :: Type Source # withExpExtended :: ExpExtended Float -> (Float -> Int -> r) -> r Source # unsafeExpExtended :: Float -> Int -> ExpExtended Float Source # expExtended :: Float -> Int -> ExpExtended Float Source # |
expExtended' :: ExpExtendable a => a -> ExpExtended a Source #
Extend the exponent range while preserving the value.
expExtended' x == expExtended x 0
unExpExtendable :: ExpExtendable a => ExpExtended a -> Bool Source #
Does the extended value fit in the base type without over/underflow?
unExpExtended :: ExpExtendable a => ExpExtended a -> a Source #
Scale to the base type (possibly overflowing to infinity or underflowing to zero).
type EDouble = ExpExtended Double Source #
type EFloat = ExpExtended Float Source #