| Portability | BangPatterns, DeriveDataTypeable, Rank2Types |
|---|---|
| Stability | unstable |
| Maintainer | claude@mathr.co.uk |
| Safe Haskell | None |
Numeric.VariablePrecision.Float
Description
Variable precision software floating point based on (Integer, Int) as used by decodeFloat. Supports infinities and NaN, but not negative zero or denormalization.
Accuracy has not been extensively verified, and termination of numerical algorithms has not been proven.
- data VFloat p
- class HasPrecision t => Normed t where
- norm1 :: NaturalNumber p => t p -> VFloat p
- norm2 :: NaturalNumber p => t p -> VFloat p
- norm2Squared :: NaturalNumber p => t p -> VFloat p
- normInfinity :: NaturalNumber p => t p -> VFloat p
- effectivePrecisionWith :: (Num t, RealFloat r) => (t -> r) -> t -> t -> Int
- effectivePrecision :: (NaturalNumber p, HasPrecision t, Normed t, Num (t p)) => t p -> t p -> Int
- (-@?) :: (NaturalNumber p, HasPrecision t, Normed t, Num (t p)) => t p -> t p -> Int
- data DFloat
- = DFloat { }
- | DZero {
- dPrecision :: !Word
- | DPositiveInfinity {
- dPrecision :: !Word
- | DNegativeInfinity {
- dPrecision :: !Word
- | DNotANumber {
- dPrecision :: !Word
- toDFloat :: NaturalNumber p => VFloat p -> DFloat
- fromDFloat :: NaturalNumber p => DFloat -> Maybe (VFloat p)
- withDFloat :: DFloat -> (forall p. NaturalNumber p => VFloat p -> r) -> r
Documentation
A software implementation of floating point arithmetic, using a strict pair of Integer and Int, scaled similarly to decodeFloat, along with additional values representing:
- positive infinity (
1/0), - negative infinity (
-1/0), - not a number (
0/0).
The Floating instance so far only implements algorithms for:
These Floating methods transit via Double and so have limited precision:
floatRange is arbitrarily limited to mitigate the problems that occur when enormous integers might be needed during some number type conversions (worst case consequence: program abort in gmp).
Instances
class HasPrecision t => Normed t whereSource
A selection of norms.
Methods
norm1 :: NaturalNumber p => t p -> VFloat pSource
norm2 :: NaturalNumber p => t p -> VFloat pSource
norm2Squared :: NaturalNumber p => t p -> VFloat pSource
normInfinity :: NaturalNumber p => t p -> VFloat pSource
A measure of meaningful precision in the difference of two finite non-zero values.
Values of very different magnitude have little meaningful difference, because a + b when approxEq a|a| >> |b|.
Very close values have little meaningful difference, because a + (a - b) as approxEq a|a| >> |a - b|.
effectivePrecisionWith attempts to quantify this.
effectivePrecision :: (NaturalNumber p, HasPrecision t, Normed t, Num (t p)) => t p -> t p -> IntSource
Much like effectivePrecisionWith combined with normInfinity.
(-@?) :: (NaturalNumber p, HasPrecision t, Normed t, Num (t p)) => t p -> t p -> IntSource
An alias for effectivePrecision.
A concrete format suitable for storage or wire transmission.
Constructors
| DFloat | |
| DZero | |
Fields
| |
| DPositiveInfinity | |
Fields
| |
| DNegativeInfinity | |
Fields
| |
| DNotANumber | |
Fields
| |
fromDFloat :: NaturalNumber p => DFloat -> Maybe (VFloat p)Source
withDFloat :: DFloat -> (forall p. NaturalNumber p => VFloat p -> r) -> rSource
Thaw a DFloat to its natural precision.