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.
Synopsis
- 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
Instances
Precision P2000 Source # | |
Defined in Data.Number.FixedPrec | |
Precision P1000 Source # | |
Defined in Data.Number.FixedPrec | |
Precision P100 Source # | |
Defined in Data.Number.FixedPrec | |
Precision P10 Source # | |
Defined in Data.Number.FixedPrec | |
Precision P1 Source # | |
Defined in Data.Number.FixedPrec | |
Precision P0 Source # | |
Defined in Data.Number.FixedPrec | |
Precision e => Precision (PPlus1000 e) Source # | |
Defined in Data.Number.FixedPrec | |
Precision e => Precision (PPlus100 e) Source # | |
Defined in Data.Number.FixedPrec | |
Precision e => Precision (PPlus10 e) Source # | |
Defined in Data.Number.FixedPrec | |
Precision e => Precision (PPlus3 e) Source # | |
Defined in Data.Number.FixedPrec | |
Precision e => Precision (PPlus1 e) Source # | |
Defined in Data.Number.FixedPrec |
Precision of 0 digits.
Precision of 1 digit.
Precision of 10 digits.
Precision of 100 digits.
Precision of 1000 digits.
Precision of 2000 digits.
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.
Instances
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.