Safe Haskell | Safe |
---|---|
Language | Haskell98 |
A reasonably efficient implementation of arbitrary-but-fixed precision real numbers. This is inspired by, and partly based on, Data.Number.Fixed and Data.Number.CReal, but more efficient.
- class Precision e
- data P0
- data P1
- data P10
- data P100
- data P1000
- data P2000
- data PPlus1 e
- data PPlus3 e
- data PPlus10 e
- data PPlus100 e
- data PPlus1000 e
- data FixedPrec e
- getprec :: Precision e => FixedPrec e -> Int
- cast :: (Precision e, Precision f) => FixedPrec e -> FixedPrec f
- upcast :: Precision e => FixedPrec e -> FixedPrec (PPlus3 e)
- downcast :: Precision e => FixedPrec (PPlus3 e) -> FixedPrec e
- with_added_digits :: forall a f. Precision f => Int -> (forall e. Precision e => FixedPrec e -> a) -> FixedPrec f -> a
- fractional :: Precision e => FixedPrec e -> FixedPrec e
- solve_quadratic :: Precision e => FixedPrec e -> FixedPrec e -> Maybe (FixedPrec e, FixedPrec e)
- log_double :: (Floating a, Real a) => a -> Double
Type-level integers for precision
A type class for type-level integers, capturing a precision parameter. Precision is measured in decimal digits.
digits
Precision P2000 Source # | |
Precision P1000 Source # | |
Precision P100 Source # | |
Precision P10 Source # | |
Precision P1 Source # | |
Precision P0 Source # | |
Precision e => Precision (PPlus1000 e) Source # | |
Precision e => Precision (PPlus100 e) Source # | |
Precision e => Precision (PPlus10 e) Source # | |
Precision e => Precision (PPlus3 e) Source # | |
Precision e => Precision (PPlus1 e) Source # | |
Add 1 digit to the given precision.
Add 3 digits to the given precision.
Add 10 digits to the given precision.
Add 100 digits to the given precision.
Add 1000 digits to the given precision.
Fixed-precision numbers
The type of fixed-precision numbers.
Eq (FixedPrec e) Source # | |
Precision e => Floating (FixedPrec e) Source # | |
Precision e => Fractional (FixedPrec e) Source # | |
Precision e => Num (FixedPrec e) Source # | |
Ord (FixedPrec e) Source # | |
Precision e => Real (FixedPrec e) Source # | |
Precision e => RealFrac (FixedPrec e) Source # | |
Precision e => Show (FixedPrec e) Source # | |
Precision e => Random (FixedPrec e) Source # | |
getprec :: Precision e => FixedPrec e -> Int Source #
Get the precision of a fixed-precision number, in decimal digits.
Static and dynamic casts
cast :: (Precision e, Precision f) => FixedPrec e -> FixedPrec f Source #
Cast from any FixedPrec
type to another.
upcast :: Precision e => FixedPrec e -> FixedPrec (PPlus3 e) Source #
Cast to a fixed-point type with three additional digits of accuracy.
downcast :: Precision e => FixedPrec (PPlus3 e) -> FixedPrec e Source #
Cast to a fixed-point type with three fewer digits of accuracy.
with_added_digits :: forall a f. Precision f => Int -> (forall e. Precision e => FixedPrec e -> a) -> FixedPrec f -> a Source #
The function with_added_digits
d f x evaluates f(x), adding
d digits of accuracy to x during the computation.
Other operations
fractional :: Precision e => FixedPrec e -> FixedPrec e Source #
Return the positive fractional part of a fixed-precision number. The result is always in [0,1), regardless of the sign of the input.
solve_quadratic :: Precision e => FixedPrec e -> FixedPrec e -> Maybe (FixedPrec e, FixedPrec e) Source #
Solve the quadratic equation x^2 + bx + c = 0 with maximal
possible precision, using a numerically stable method. Return the
pair (x1, x2) of solutions with x1 <= x2, or Nothing
if no
solution exists.
This is far more precise, and probably more efficient, than naively using the quadratic formula.