Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Simple decimal arithmetic.
Deka
provides a decimal arithmetic type. Using this module, the
results are never inexact. Computations will throw exceptions
rather than returning an inexact result. That way, you know that
any result you have is exactly correct.
On 64-bit platforms, you are limited to:
- a coefficient of ((2 * 10 ^ 17) - 1) digits long
- a maximum exponent of ((1 * 10 ^ 18) - 1)
- a minimum exponent of -((1 * 10 ^ 18) + 1)
On 32-bit platforms, you are limited to:
- a coefficient of 8.5 * 10 ^ 8 digits long
- a maximum exponent of 4.25 * 10 ^ 8
- a minimum exponent of -4.25 * 10 ^ 8
If you exceed these limits, your computation will throw an exception.
Deka
represents only finite values. There are no infinities or
not-a-number values allowed.
For more control over your arithmetic, see Deka.Dec, but
for many routine uses this module is sufficient and is more
succinct because, unlike D.Dec
, Deka
is a member of the Num
typeclass.
Documentation
Deka wraps a D.Dec
. Only finite D.Dec
may become a Deka
;
no infinities or NaN values are allowed.
Deka
is a member of Num
, making it easy to use for
elementary arithmetic. Any time you perform arithmetic, the
results are always exact. The arithmetic functions will throw
exceptions rather than give you an inexact result.
Deka
is not a member Fractional
because it is generally
impossible to perform division without getting inexact results,
and Deka
never holds inexact results.
Eq Deka | Eq compares by value. For instance, |
Num Deka | Many of the |
Ord Deka | Ord compares by value. For instance, |
Show Deka |
Decimals with a total ordering.
strToDeka :: String -> Maybe Deka Source
Convert a string to a Deka. You can use ordinary numeric
strings, such as 3.25
, or exponential notation, like 325E-2
.
More information on your choices is at:
http://speleotrove.com/decimal/daconvs.html#reftonum
You cannot use strings that represent an NaN or an infinity. If
you do that, or use an otherwise invalid string, this function
returns Nothing
.