Safe Haskell | Safe |
---|
Simple decimal arithmetic.
Deka
provides a decimal arithmetic type. You are limited to 34
digits of precision. That's 34 digits total, not 34 digits after
the decimal point. For example, the numbers 123.0
and 0.1230
both have four digits of precision. Deka remembers significant
digits, so 123
has three digits of precision while 123.0
has
four digits of precision.
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.
Deka
represents only finite values. There are no infinities or
not-a-number values allowed.
For more control over your arithmetic, see Data.Deka.Quad, but
for many routine uses this module is sufficient and is more
succinct because, unlike Quad
, Deka
is a member of the Num
typeclass.
Documentation
Deka wraps a Quad
. Only finite Quad
may become a Deka
;
no infinities or NaN values are allowed.
Deka
is a member of Num
and Real
, 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.
Bounded Deka | |
Eq Deka | Eq compares by value. For instance, |
Num Deka | Many of the |
Ord Deka | Ord compares by value. For instance, |
Real Deka | |
Show Deka |
Decimals with a total ordering.
integralToDeka :: Integral a => a -> Maybe DekaSource
Convert any integral to a Deka. Returns Nothing
if the
integer is too big to fit into a Deka (34 digits).
strToDeka :: String -> Maybe DekaSource
Convert a string to a Deka. You can use ordinary numeric
strings, such as 3.25
, or exponential notation, like 325E-2
.
More infomration 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
.
quadToDeka :: Quad -> Maybe DekaSource
Change a Quad to a Deka. Only succeeds for finite Quad.
Thrown by arithmetic functions in the Num class, as this is the only way to indicate errors.
IntegerTooBig Integer | Could not convert an integer to a Deka; it is too big. |
Flagged Flags | A computation set flags. This will happen if, for example, you calculate a result that is out of range, such as
|