Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Numeric.ExpExtended
Description
Extend floating point types with a larger exponent range.
- 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.
Minimal complete definition
Associated Types
data ExpExtended a Source
Methods
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
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