Portability | BangPatterns, DeriveDataTypeable, Rank2Types |
---|---|
Stability | unstable |
Maintainer | claudiusmaximus@goto10.org |
Safe Haskell | Safe-Infered |
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).
Typeable1 VFloat | |
VariablePrecision VFloat | |
HasPrecision VFloat | |
Normed VFloat | |
Eq (VFloat p) | |
NaturalNumber p => Floating (VFloat p) | |
NaturalNumber p => Fractional (VFloat p) | |
Data p => Data (VFloat p) | |
NaturalNumber p => Num (VFloat p) | |
Ord (VFloat p) | |
NaturalNumber p => Read (VFloat p) | |
NaturalNumber p => Real (VFloat p) | |
NaturalNumber p => RealFloat (VFloat p) | |
NaturalNumber p => RealFrac (VFloat p) | |
NaturalNumber p => Show (VFloat p) | |
NaturalNumber p => DispFloat (VFloat p) | |
NaturalNumber p => FShow (VFloat p) |
class HasPrecision t => Normed t whereSource
A selection of norms.
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.
DFloat | |
DZero | |
| |
DPositiveInfinity | |
| |
DNegativeInfinity | |
| |
DNotANumber | |
|
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.