Safe Haskell | None |
---|---|
Language | Haskell2010 |
Numeric.Decimal
Synopsis
- module Numeric.Decimal.BoundedArithmetic
- absDecimal :: forall (s :: Nat) r. KnownNat s => Decimal r s Integer -> Decimal r s Integer
- absDecimalBounded :: forall (s :: Nat) m p r. (KnownNat s, MonadThrow m, Integral p, Bounded p) => Decimal r s p -> m (Decimal r s p)
- arithD :: forall r (s :: Nat) p. Arith (Decimal r s p) -> Arith (Decimal r s p)
- arithEitherD :: forall r (s :: Nat) p. Arith (Decimal r s p) -> Either SomeException (Decimal r s p)
- arithMD :: forall r (s :: Nat) p m. MonadThrow m => Arith (Decimal r s p) -> m (Decimal r s p)
- arithMaybeD :: forall r (s :: Nat) p. Arith (Decimal r s p) -> Maybe (Decimal r s p)
- arithRoundD :: forall (s' :: Natural) r (s :: Natural) p (k :: Nat). (Round r p, KnownNat k, s ~ (s' + k)) => Arith (Decimal r s p) -> Arith (Decimal r s' p)
- bindM2 :: Monad m => (a -> b -> m c) -> m a -> m b -> m c
- bindM2Decimal :: forall m p1 p2 p r1 (s1 :: Nat) r2 (s2 :: Nat) r (s :: Nat). Monad m => (p1 -> p2 -> m p) -> m (Decimal r1 s1 p1) -> m (Decimal r2 s2 p2) -> m (Decimal r s p)
- castRounding :: forall r' r (s :: Nat) p. Decimal r s p -> Decimal r' s p
- decimalDenominator :: forall (s :: Nat) r p. KnownNat s => Decimal r s p -> Integer
- decimalNumerator :: forall p r (s :: Nat). Integral p => Decimal r s p -> Integer
- divideDecimalBoundedWithRounding :: forall m (s :: Nat) r p. (MonadThrow m, KnownNat s, Round r Integer, Bounded p, Integral p) => Decimal r s p -> Decimal r s p -> m (Decimal r s p)
- divideDecimalBoundedWithoutLoss :: forall r (s :: Nat) p m. (Integral p, Bounded p, KnownNat s, MonadThrow m) => Decimal r s p -> Decimal r s p -> m (Decimal r s p)
- divideDecimalWithRounding :: forall m (s :: Nat) r. (MonadThrow m, KnownNat s, Round r Integer) => Decimal r s Integer -> Decimal r s Integer -> m (Decimal r s Integer)
- divideDecimalWithoutLoss :: forall r (s :: Nat) m. (KnownNat s, MonadThrow m) => Decimal r s Integer -> Decimal r s Integer -> m (Decimal r s Integer)
- fromIntegerDecimal :: forall r (s :: Nat). KnownNat s => Integer -> Decimal r s Integer
- fromIntegerDecimalBounded :: forall m r (s :: Nat) p. (MonadThrow m, Integral p, Bounded p) => Decimal r s Integer -> m (Decimal r s p)
- fromIntegerDecimalBoundedIntegral :: forall m r (s :: Nat) p. (MonadThrow m, Integral p, Bounded p, KnownNat s) => Integer -> m (Decimal r s p)
- fromIntegralDecimalBounded :: forall p (s :: Nat) m r. (Integral p, Bounded p, KnownNat s, MonadThrow m) => p -> m (Decimal r s p)
- fromRationalDecimalBoundedWithRounding :: forall m r (s :: Nat) p. (MonadThrow m, KnownNat s, Round r Integer, Bounded p, Integral p) => Rational -> m (Decimal r s p)
- fromRationalDecimalBoundedWithoutLoss :: forall m (s :: Nat) p r. (MonadThrow m, KnownNat s, Integral p, Bounded p) => Rational -> m (Decimal r s p)
- fromRationalDecimalWithRounding :: forall m r (s :: Nat). (MonadThrow m, KnownNat s, Round r Integer) => Rational -> m (Decimal r s Integer)
- fromRationalDecimalWithoutLoss :: forall m r (s :: Nat). (MonadThrow m, KnownNat s) => Rational -> m (Decimal r s Integer)
- getScale :: forall r (s :: Nat) p. KnownNat s => Decimal r s p -> Integer
- integralDecimalToDecimalBounded :: forall p' p (s :: Nat) m r. (Integral p', Integral p, Bounded p, KnownNat s, MonadThrow m) => Decimal r s p' -> m (Decimal r s p)
- minusDecimal :: forall r (s :: Nat). Decimal r s Integer -> Decimal r s Integer -> Decimal r s Integer
- minusDecimalBounded :: forall m p r (s :: Nat). (MonadThrow m, Eq p, Ord p, Num p, Bounded p) => Decimal r s p -> Decimal r s p -> m (Decimal r s p)
- parseDecimalBounded :: forall r (s :: Nat) p. (KnownNat s, Bounded p, Integral p) => Bool -> String -> Either String (Decimal r s p)
- plusDecimal :: forall r (s :: Nat). Decimal r s Integer -> Decimal r s Integer -> Decimal r s Integer
- plusDecimalBounded :: forall m p r (s :: Nat). (MonadThrow m, Eq p, Ord p, Num p, Bounded p) => Decimal r s p -> Decimal r s p -> m (Decimal r s p)
- quotRemDecimalBounded :: forall m r (s :: Nat) p. (MonadThrow m, Integral p, Bounded p) => Decimal r s p -> Integer -> m (Decimal r s p, Decimal r s p)
- scaleUp :: forall (k :: Nat) r (n :: Nat). KnownNat k => Decimal r n Integer -> Decimal r (n + k) Integer
- scaleUpBounded :: forall (k :: Nat) r (n :: Nat) p m. (MonadThrow m, Integral p, Bounded p, KnownNat k) => Decimal r n p -> m (Decimal r (n + k) p)
- signumDecimal :: forall (s :: Nat) r. KnownNat s => Decimal r s Integer -> Decimal r s Integer
- signumDecimalBounded :: forall (s :: Nat) m p r. (KnownNat s, MonadThrow m, Integral p, Bounded p) => Decimal r s p -> m (Decimal r s p)
- splitDecimal :: forall p (s :: Nat) r. (Integral p, KnownNat s) => Decimal r s p -> (p, p)
- timesDecimal :: forall r (s1 :: Nat) (s2 :: Nat). Decimal r s1 Integer -> Decimal r s2 Integer -> Decimal r (s1 + s2) Integer
- timesDecimalBounded :: forall m p r (s1 :: Nat) (s2 :: Nat). (MonadThrow m, Integral p, Bounded p) => Decimal r s1 p -> Decimal r s2 p -> m (Decimal r (s1 + s2) p)
- timesDecimalBoundedWithRounding :: forall m (s :: Nat) r p. (MonadThrow m, KnownNat s, Round r Integer, Integral p, Bounded p) => Decimal r s p -> Decimal r s p -> m (Decimal r s p)
- timesDecimalBoundedWithoutLoss :: forall r (s :: Nat) p m. (Integral p, Bounded p, KnownNat s, MonadThrow m) => Decimal r s p -> Decimal r s p -> m (Decimal r s p)
- timesDecimalWithRounding :: forall (s :: Nat) r. (KnownNat s, Round r Integer) => Decimal r s Integer -> Decimal r s Integer -> Decimal r s Integer
- timesDecimalWithoutLoss :: forall r (s :: Nat) m. (KnownNat s, MonadThrow m) => Decimal r s Integer -> Decimal r s Integer -> m (Decimal r s Integer)
- toRationalDecimal :: forall (s :: Nat) p r. (KnownNat s, Integral p) => Decimal r s p -> Rational
- unwrapDecimal :: forall r (s :: Nat) p. Decimal r s p -> p
- wrapDecimal :: forall p r (s :: Nat). Integral p => p -> Decimal r s p
- class Monad m => MonadThrow (m :: Type -> Type) where
- throwM :: (HasCallStack, Exception e) => e -> m a
- data ArithException
- data SomeException
- newtype Decimal r (s :: Nat) p = Decimal p
- class Integral p => Round r p where
- data RoundHalfUp
- roundHalfUp :: forall r (n :: Natural) (k :: Nat) p. (Integral p, KnownNat k) => Decimal r (n + k) p -> Decimal r n p
- data RoundHalfDown
- roundHalfDown :: forall r (n :: Natural) (k :: Nat) p. (Integral p, KnownNat k) => Decimal r (n + k) p -> Decimal r n p
- data RoundHalfEven
- roundHalfEven :: forall r (n :: Natural) (k :: Nat) p. (Integral p, KnownNat k) => Decimal r (n + k) p -> Decimal r n p
- data RoundHalfToZero
- roundHalfToZero :: forall r (n :: Natural) (k :: Nat) p. (Integral p, KnownNat k) => Decimal r (n + k) p -> Decimal r n p
- data RoundHalfFromZero
- roundHalfFromZero :: forall r (n :: Natural) (k :: Nat) p. (Integral p, KnownNat k) => Decimal r (n + k) p -> Decimal r n p
- data RoundDown
- type Floor = RoundDown
- roundDown :: forall r (n :: Natural) (k :: Nat) p. (Integral p, KnownNat k) => Decimal r (n + k) p -> Decimal r n p
- data RoundToZero
- type Truncate = RoundToZero
- roundToZero :: forall r (n :: Natural) (k :: Nat) p. (Integral p, KnownNat k) => Decimal r (n + k) p -> Decimal r n p
- decimalList :: forall p r (s :: Nat). Integral p => [p] -> [Decimal r s p]
- sumDecimalBounded :: forall m f p r (s :: Nat). (MonadThrow m, Foldable f, Eq p, Ord p, Num p, Bounded p) => f (Decimal r s p) -> m (Decimal r s p)
- productDecimalBoundedWithRounding :: forall m f (s :: Nat) r p. (MonadThrow m, Foldable f, KnownNat s, Round r Integer, Integral p, Bounded p) => f (Decimal r s p) -> m (Decimal r s p)
- type family FixedScale e :: Nat
- toFixedDecimal :: forall (s :: Nat) e p r. (s ~ FixedScale e, Integral p) => Decimal r s p -> Fixed e
- fromFixedDecimal :: forall (s :: Nat) e r. s ~ FixedScale e => Fixed e -> Decimal r s Integer
- fromFixedDecimalBounded :: forall (s :: Nat) e m p r. (s ~ FixedScale e, MonadThrow m, Integral p, Bounded p) => Fixed e -> m (Decimal r s p)
- toScientificDecimal :: forall p (s :: Nat) r. (Integral p, KnownNat s) => Decimal r s p -> Scientific
- fromScientificDecimal :: forall m r (s :: Nat). (MonadThrow m, KnownNat s) => Scientific -> m (Decimal r s Integer)
- fromScientificDecimalBounded :: forall m r (s :: Nat) p. (MonadThrow m, Integral p, Bounded p, KnownNat s) => Scientific -> m (Decimal r s p)
Arithmetic
absDecimal :: forall (s :: Nat) r. KnownNat s => Decimal r s Integer -> Decimal r s Integer Source #
Compute absolute value of a decimal
Since: 0.2.0
absDecimalBounded :: forall (s :: Nat) m p r. (KnownNat s, MonadThrow m, Integral p, Bounded p) => Decimal r s p -> m (Decimal r s p) Source #
Compute absolute value of a bounded decimal. Protects against overflows for negative
minBound
.
>>>
abs (minBound :: Int8)
-128>>>
import Numeric.Decimal
>>>
d <- arithM (fromRational (-1.28) :: Arith (Decimal RoundHalfUp 2 Int8))
>>>
d
-1.28>>>
absDecimalBounded d :: Either SomeException (Decimal RoundHalfUp 2 Int8)
Left arithmetic overflow
Note - Watch out for order of negation
>>>
-1.28 :: Arith (Decimal RoundHalfUp 2 Int8)
ArithError arithmetic overflow>>>
negate (1.28 :: Arith (Decimal RoundHalfUp 2 Int8))
ArithError arithmetic overflow>>>
:set -XNegativeLiterals
>>>
-1.28 :: Arith (Decimal RoundHalfUp 2 Int8)
Arith -1.28
Since: 0.2.0
arithD :: forall r (s :: Nat) p. Arith (Decimal r s p) -> Arith (Decimal r s p) Source #
A way to type restrict a polymorphic computation.
arithD
provide an easy way to use TypeApplications
to supply a type of Decimal:
>>>
import Numeric.Decimal
>>>
:set -XTypeApplications
>>>
arithM $ arithD @RoundDown @3 @Word (1.1 + 123)
124.100>>>
arithM $ arithD @RoundDown @3 @Word (1.1 - 123)
*** Exception: arithmetic underflow
Since: 0.2.0
arithEitherD :: forall r (s :: Nat) p. Arith (Decimal r s p) -> Either SomeException (Decimal r s p) Source #
arithMD :: forall r (s :: Nat) p m. MonadThrow m => Arith (Decimal r s p) -> m (Decimal r s p) Source #
A way to type restrict a polymorphic computation.
arithD
provide an easy way to use TypeApplications
to supply a type of Decimal:
>>>
import Numeric.Decimal
>>>
:set -XDataKinds -XTypeApplications
>>>
arithMD @RoundDown @3 @Word (1.1 + 123)
124.100>>>
arithMD @RoundDown @3 @Word (1.1 - 123)
*** Exception: arithmetic underflow
Since: 0.2.0
arithRoundD :: forall (s' :: Natural) r (s :: Natural) p (k :: Nat). (Round r p, KnownNat k, s ~ (s' + k)) => Arith (Decimal r s p) -> Arith (Decimal r s' p) Source #
A way to type restrict a polymorphic computation.
>>>
import Numeric.Decimal
>>>
arithRoundD @1 @RoundDown @2 @Word (123.05 + 1.1)
Arith 124.1
Since: 0.2.0
bindM2Decimal :: forall m p1 p2 p r1 (s1 :: Nat) r2 (s2 :: Nat) r (s :: Nat). Monad m => (p1 -> p2 -> m p) -> m (Decimal r1 s1 p1) -> m (Decimal r2 s2 p2) -> m (Decimal r s p) Source #
castRounding :: forall r' r (s :: Nat) p. Decimal r s p -> Decimal r' s p Source #
Change the rounding strategy of a Decimal
>>>
import Numeric.Decimal
>>>
:set -XDataKinds -XTypeApplications
>>>
d <- arithMD @RoundHalfUp @3 @Int 123.45
>>>
roundDecimal d :: Decimal RoundHalfUp 1 Int
123.5>>>
:t castRounding @RoundDown d
castRounding @RoundDown d :: Decimal RoundDown 3 Int>>>
roundDecimal (castRounding d) :: Decimal RoundDown 1 Int
123.4
Since: 0.2.0
decimalDenominator :: forall (s :: Nat) r p. KnownNat s => Decimal r s p -> Integer Source #
Get the decimal denominator. Always will be a multiple of 10
. Does not evaluate the
argument.
>>>
import Numeric.Decimal
>>>
:set -XDataKinds -XTypeApplications
>>>
decimalDenominator <$> arithD @RoundHalfEven @3 @Int 123.45
Arith 1000
Since: 0.2.0
decimalNumerator :: forall p r (s :: Nat). Integral p => Decimal r s p -> Integer Source #
Get the numerator. Same as toInteger
. unwrapDecimal
>>>
import Numeric.Decimal
>>>
:set -XDataKinds -XTypeApplications
>>>
decimalNumerator <$> arithD @RoundHalfEven @3 @Int 123.45
Arith 123450
Since: 0.2.0
divideDecimalBoundedWithRounding :: forall m (s :: Nat) r p. (MonadThrow m, KnownNat s, Round r Integer, Bounded p, Integral p) => Decimal r s p -> Decimal r s p -> m (Decimal r s p) Source #
divideDecimalBoundedWithoutLoss :: forall r (s :: Nat) p m. (Integral p, Bounded p, KnownNat s, MonadThrow m) => Decimal r s p -> Decimal r s p -> m (Decimal r s p) Source #
Divide two decimal numbers that have the same scale, while throwing PrecisionLoss
whenever division cannot be done without rounding.
Since: 0.2.0
divideDecimalWithRounding :: forall m (s :: Nat) r. (MonadThrow m, KnownNat s, Round r Integer) => Decimal r s Integer -> Decimal r s Integer -> m (Decimal r s Integer) Source #
divideDecimalWithoutLoss :: forall r (s :: Nat) m. (KnownNat s, MonadThrow m) => Decimal r s Integer -> Decimal r s Integer -> m (Decimal r s Integer) Source #
Divide two decimal numbers that have the same scale, while throwing PrecisionLoss
whenever division cannot be done without rounding.
Since: 0.2.0
fromIntegerDecimal :: forall r (s :: Nat). KnownNat s => Integer -> Decimal r s Integer Source #
Convert an Integer
while performing the necessary scaling
>>>
import Numeric.Decimal
>>>
fromIntegerDecimal 1234 :: Decimal RoundHalfUp 4 Integer
1234.0000
Since: 0.2.0
fromIntegerDecimalBounded :: forall m r (s :: Nat) p. (MonadThrow m, Integral p, Bounded p) => Decimal r s Integer -> m (Decimal r s p) Source #
fromIntegerDecimalBoundedIntegral :: forall m r (s :: Nat) p. (MonadThrow m, Integral p, Bounded p, KnownNat s) => Integer -> m (Decimal r s p) Source #
Convert an Integer to a Decimal backed by a bounded integral while doing proper scaling and checking the bounds.
Since: 0.2.0
fromIntegralDecimalBounded :: forall p (s :: Nat) m r. (Integral p, Bounded p, KnownNat s, MonadThrow m) => p -> m (Decimal r s p) Source #
Convert a bounded integeral into a decimal, while performing the necessary scaling
>>>
import Numeric.Decimal
>>>
fromIntegralDecimalBounded 1234 :: IO (Decimal RoundHalfUp 4 Int)
1234.0000>>>
fromIntegralDecimalBounded 1234 :: IO (Decimal RoundHalfUp 4 Int16)
*** Exception: arithmetic overflow
Since: 0.2.0
fromRationalDecimalBoundedWithRounding :: forall m r (s :: Nat) p. (MonadThrow m, KnownNat s, Round r Integer, Bounded p, Integral p) => Rational -> m (Decimal r s p) Source #
fromRationalDecimalBoundedWithoutLoss :: forall m (s :: Nat) p r. (MonadThrow m, KnownNat s, Integral p, Bounded p) => Rational -> m (Decimal r s p) Source #
fromRationalDecimalWithRounding :: forall m r (s :: Nat). (MonadThrow m, KnownNat s, Round r Integer) => Rational -> m (Decimal r s Integer) Source #
fromRationalDecimalWithoutLoss :: forall m r (s :: Nat). (MonadThrow m, KnownNat s) => Rational -> m (Decimal r s Integer) Source #
Convert from Rational
to a Decimal
backed by Integer
. PrecisionLoss
will be
thrown if conversion cannot be achieved without any loss of data. In case that rounding
is acceptable use fromRationalDecimalBoundedWithRounding
Since: 0.2.0
getScale :: forall r (s :: Nat) p. KnownNat s => Decimal r s p -> Integer Source #
Get the scale of a Decimal
. Argument is not evaluated.
>>>
import Numeric.Decimal
>>>
d <- arithM (36 :: Arith (Decimal RoundHalfUp 5 Int))
>>>
d
36.00000>>>
getScale d
5
Since: 0.1.0
integralDecimalToDecimalBounded :: forall p' p (s :: Nat) m r. (Integral p', Integral p, Bounded p, KnownNat s, MonadThrow m) => Decimal r s p' -> m (Decimal r s p) Source #
Convert a decimal backed by an integral to another decimal backed by a bounded
integeral, while checking for Overflow
/Underflow
>>>
import Numeric.Decimal
>>>
fromIntegralDecimalBounded 1234 :: IO (Decimal RoundHalfUp 4 Int)
1234.0000>>>
fromIntegralDecimalBounded 1234 :: IO (Decimal RoundHalfUp 4 Int16)
*** Exception: arithmetic overflow
Since: 0.2.0
minusDecimal :: forall r (s :: Nat). Decimal r s Integer -> Decimal r s Integer -> Decimal r s Integer Source #
Subtract two decimal numbers backed by Integer
.
Since: 0.1.0
minusDecimalBounded :: forall m p r (s :: Nat). (MonadThrow m, Eq p, Ord p, Num p, Bounded p) => Decimal r s p -> Decimal r s p -> m (Decimal r s p) Source #
Subtract two decimal numbers.
Since: 0.1.0
parseDecimalBounded :: forall r (s :: Nat) p. (KnownNat s, Bounded p, Integral p) => Bool -> String -> Either String (Decimal r s p) Source #
plusDecimal :: forall r (s :: Nat). Decimal r s Integer -> Decimal r s Integer -> Decimal r s Integer Source #
Add two decimal numbers backed by Integer
.
Since: 0.1.0
plusDecimalBounded :: forall m p r (s :: Nat). (MonadThrow m, Eq p, Ord p, Num p, Bounded p) => Decimal r s p -> Decimal r s p -> m (Decimal r s p) Source #
Add two decimal numbers.
Since: 0.1.0
quotRemDecimalBounded :: forall m r (s :: Nat) p. (MonadThrow m, Integral p, Bounded p) => Decimal r s p -> Integer -> m (Decimal r s p, Decimal r s p) Source #
scaleUp :: forall (k :: Nat) r (n :: Nat). KnownNat k => Decimal r n Integer -> Decimal r (n + k) Integer Source #
Increase the precision of a Decimal
, use roundDecimal
if inverse is desired.
>>>
import Numeric.Decimal
>>>
d2 <- arithM (1.65 :: Arith (Decimal RoundHalfUp 2 Integer))
>>>
d2
1.65>>>
scaleUp d2 :: Decimal RoundHalfUp 50 Integer
1.65000000000000000000000000000000000000000000000000
Since: 0.2.0
scaleUpBounded :: forall (k :: Nat) r (n :: Nat) p m. (MonadThrow m, Integral p, Bounded p, KnownNat k) => Decimal r n p -> m (Decimal r (n + k) p) Source #
Increase the precision of a Decimal
backed by a bounded type, use roundDecimal
if
inverse is desired.
>>>
import Numeric.Decimal
>>>
d2 <- arithM (1.65 :: Arith (Decimal RoundHalfUp 2 Int16))
>>>
scaleUpBounded d2 :: IO (Decimal RoundHalfUp 3 Int16)
1.650>>>
scaleUpBounded d2 :: IO (Decimal RoundHalfUp 4 Int16)
1.6500>>>
scaleUpBounded d2 :: IO (Decimal RoundHalfUp 5 Int16)
*** Exception: arithmetic overflow
Since: 0.1.1
signumDecimal :: forall (s :: Nat) r. KnownNat s => Decimal r s Integer -> Decimal r s Integer Source #
Compute signum of a decimal, always one of 1, 0 or -1
Since: 0.2.0
signumDecimalBounded :: forall (s :: Nat) m p r. (KnownNat s, MonadThrow m, Integral p, Bounded p) => Decimal r s p -> m (Decimal r s p) Source #
Compute signum of a decimal, always one of 1, 0 or -1
splitDecimal :: forall p (s :: Nat) r. (Integral p, KnownNat s) => Decimal r s p -> (p, p) Source #
Split the number at the decimal point, i.e. whole number and the fraction
>>>
import Numeric.Decimal
>>>
splitDecimal <$> (12.34 :: Arith (Decimal RoundHalfUp 2 Int))
Arith (12,34)
Since: 0.1.0
timesDecimal :: forall r (s1 :: Nat) (s2 :: Nat). Decimal r s1 Integer -> Decimal r s2 Integer -> Decimal r (s1 + s2) Integer Source #
Multiply two bounded decimal numbers, adjusting their scale at the type level as well.
Since: 0.1.0
timesDecimalBounded :: forall m p r (s1 :: Nat) (s2 :: Nat). (MonadThrow m, Integral p, Bounded p) => Decimal r s1 p -> Decimal r s2 p -> m (Decimal r (s1 + s2) p) Source #
Multiply two bounded decimal numbers, adjusting their scale at the type level as well.
Since: 0.1.0
timesDecimalBoundedWithRounding :: forall m (s :: Nat) r p. (MonadThrow m, KnownNat s, Round r Integer, Integral p, Bounded p) => Decimal r s p -> Decimal r s p -> m (Decimal r s p) Source #
Multiply two decimal numbers, while rounding the result according to the rounding strategy.
Since: 0.2.0
timesDecimalBoundedWithoutLoss :: forall r (s :: Nat) p m. (Integral p, Bounded p, KnownNat s, MonadThrow m) => Decimal r s p -> Decimal r s p -> m (Decimal r s p) Source #
timesDecimalWithRounding :: forall (s :: Nat) r. (KnownNat s, Round r Integer) => Decimal r s Integer -> Decimal r s Integer -> Decimal r s Integer Source #
Multiply two decimal numbers backed by Integer
, while rounding the result according
to the rounding strategy.
Since: 0.2.0
timesDecimalWithoutLoss :: forall r (s :: Nat) m. (KnownNat s, MonadThrow m) => Decimal r s Integer -> Decimal r s Integer -> m (Decimal r s Integer) Source #
Multiply two decimal numbers that have the same scale, while throwing PrecisionLoss
whenever multiplication cannot be done without rounding.
Since: 0.2.0
toRationalDecimal :: forall (s :: Nat) p r. (KnownNat s, Integral p) => Decimal r s p -> Rational Source #
Convert a decimal to a Rational
Since: 0.2.0
unwrapDecimal :: forall r (s :: Nat) p. Decimal r s p -> p Source #
Get out the underlying representation for the decimal number. No scaling will be done.
>>>
import Numeric.Decimal
>>>
unwrapDecimal (wrapDecimal 1234 :: Decimal RoundHalfUp 4 Int)
1234
Since: 0.1.0
class Monad m => MonadThrow (m :: Type -> Type) where #
A class for monads in which exceptions may be thrown.
Instances should obey the following law:
throwM e >> x = throwM e
In other words, throwing an exception short-circuits the rest of the monadic computation.
Methods
throwM :: (HasCallStack, Exception e) => e -> m a #
Throw an exception. Note that this throws when this action is run in
the monad m
, not when it is applied. It is a generalization of
Control.Exception's throwIO
.
Should satisfy the law:
throwM e >> f = throwM e
Instances
data ArithException #
Arithmetic exceptions.
Constructors
Overflow | |
Underflow | |
LossOfPrecision | |
DivideByZero | |
Denormal | |
RatioZeroDenominator | Since: base-4.6.0.0 |
Instances
data SomeException #
The SomeException
type is the root of the exception type hierarchy.
When an exception of type e
is thrown, behind the scenes it is
encapsulated in a SomeException
.
Instances
Exception SomeException # | This drops any attached Since: base-3.0 |
Defined in GHC.Internal.Exception.Type Methods toException :: SomeException -> SomeException # fromException :: SomeException -> Maybe SomeException # displayException :: SomeException -> String # backtraceDesired :: SomeException -> Bool # | |
Show SomeException # | Since: ghc-internal-3.0 |
Defined in GHC.Internal.Exception.Type Methods showsPrec :: Int -> SomeException -> ShowS # show :: SomeException -> String # showList :: [SomeException] -> ShowS # |
newtype Decimal r (s :: Nat) p Source #
Decimal number with custom precision (p
) and type level scaling (s
) parameter (i.e. number
of digits after the decimal point). As well as the rounding (r
) strategy to use.
Constructors
Decimal p |
Instances
class Integral p => Round r p where Source #
Rounding strategy to be used with decimal numbers.
Since: 0.1.0
Methods
roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal r (n + k) p -> Decimal r n p Source #
Reduce the scale of a number by k
decimal places using rounding strategy r
Since: 0.1.0
Instances
Round RoundDown Int16 Source # | |
Round RoundDown Int32 Source # | |
Round RoundDown Int64 Source # | |
Round RoundDown Int8 Source # | |
Round RoundDown Word16 Source # | |
Round RoundDown Word32 Source # | |
Round RoundDown Word64 Source # | |
Round RoundDown Word8 Source # | |
Round RoundDown Integer Source # | |
Round RoundDown Int Source # | |
Round RoundDown Word Source # | |
Round RoundHalfDown Int16 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfDown (n + k) Int16 -> Decimal RoundHalfDown n Int16 Source # | |
Round RoundHalfDown Int32 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfDown (n + k) Int32 -> Decimal RoundHalfDown n Int32 Source # | |
Round RoundHalfDown Int64 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfDown (n + k) Int64 -> Decimal RoundHalfDown n Int64 Source # | |
Round RoundHalfDown Int8 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfDown (n + k) Int8 -> Decimal RoundHalfDown n Int8 Source # | |
Round RoundHalfDown Word16 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfDown (n + k) Word16 -> Decimal RoundHalfDown n Word16 Source # | |
Round RoundHalfDown Word32 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfDown (n + k) Word32 -> Decimal RoundHalfDown n Word32 Source # | |
Round RoundHalfDown Word64 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfDown (n + k) Word64 -> Decimal RoundHalfDown n Word64 Source # | |
Round RoundHalfDown Word8 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfDown (n + k) Word8 -> Decimal RoundHalfDown n Word8 Source # | |
Round RoundHalfDown Integer Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfDown (n + k) Integer -> Decimal RoundHalfDown n Integer Source # | |
Round RoundHalfDown Int Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfDown (n + k) Int -> Decimal RoundHalfDown n Int Source # | |
Round RoundHalfDown Word Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfDown (n + k) Word -> Decimal RoundHalfDown n Word Source # | |
Round RoundHalfEven Int16 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfEven (n + k) Int16 -> Decimal RoundHalfEven n Int16 Source # | |
Round RoundHalfEven Int32 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfEven (n + k) Int32 -> Decimal RoundHalfEven n Int32 Source # | |
Round RoundHalfEven Int64 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfEven (n + k) Int64 -> Decimal RoundHalfEven n Int64 Source # | |
Round RoundHalfEven Int8 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfEven (n + k) Int8 -> Decimal RoundHalfEven n Int8 Source # | |
Round RoundHalfEven Word16 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfEven (n + k) Word16 -> Decimal RoundHalfEven n Word16 Source # | |
Round RoundHalfEven Word32 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfEven (n + k) Word32 -> Decimal RoundHalfEven n Word32 Source # | |
Round RoundHalfEven Word64 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfEven (n + k) Word64 -> Decimal RoundHalfEven n Word64 Source # | |
Round RoundHalfEven Word8 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfEven (n + k) Word8 -> Decimal RoundHalfEven n Word8 Source # | |
Round RoundHalfEven Integer Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfEven (n + k) Integer -> Decimal RoundHalfEven n Integer Source # | |
Round RoundHalfEven Int Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfEven (n + k) Int -> Decimal RoundHalfEven n Int Source # | |
Round RoundHalfEven Word Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfEven (n + k) Word -> Decimal RoundHalfEven n Word Source # | |
Round RoundHalfFromZero Int16 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfFromZero (n + k) Int16 -> Decimal RoundHalfFromZero n Int16 Source # | |
Round RoundHalfFromZero Int32 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfFromZero (n + k) Int32 -> Decimal RoundHalfFromZero n Int32 Source # | |
Round RoundHalfFromZero Int64 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfFromZero (n + k) Int64 -> Decimal RoundHalfFromZero n Int64 Source # | |
Round RoundHalfFromZero Int8 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfFromZero (n + k) Int8 -> Decimal RoundHalfFromZero n Int8 Source # | |
Round RoundHalfFromZero Word16 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfFromZero (n + k) Word16 -> Decimal RoundHalfFromZero n Word16 Source # | |
Round RoundHalfFromZero Word32 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfFromZero (n + k) Word32 -> Decimal RoundHalfFromZero n Word32 Source # | |
Round RoundHalfFromZero Word64 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfFromZero (n + k) Word64 -> Decimal RoundHalfFromZero n Word64 Source # | |
Round RoundHalfFromZero Word8 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfFromZero (n + k) Word8 -> Decimal RoundHalfFromZero n Word8 Source # | |
Round RoundHalfFromZero Integer Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfFromZero (n + k) Integer -> Decimal RoundHalfFromZero n Integer Source # | |
Round RoundHalfFromZero Int Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfFromZero (n + k) Int -> Decimal RoundHalfFromZero n Int Source # | |
Round RoundHalfFromZero Word Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfFromZero (n + k) Word -> Decimal RoundHalfFromZero n Word Source # | |
Round RoundHalfToZero Int16 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfToZero (n + k) Int16 -> Decimal RoundHalfToZero n Int16 Source # | |
Round RoundHalfToZero Int32 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfToZero (n + k) Int32 -> Decimal RoundHalfToZero n Int32 Source # | |
Round RoundHalfToZero Int64 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfToZero (n + k) Int64 -> Decimal RoundHalfToZero n Int64 Source # | |
Round RoundHalfToZero Int8 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfToZero (n + k) Int8 -> Decimal RoundHalfToZero n Int8 Source # | |
Round RoundHalfToZero Word16 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfToZero (n + k) Word16 -> Decimal RoundHalfToZero n Word16 Source # | |
Round RoundHalfToZero Word32 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfToZero (n + k) Word32 -> Decimal RoundHalfToZero n Word32 Source # | |
Round RoundHalfToZero Word64 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfToZero (n + k) Word64 -> Decimal RoundHalfToZero n Word64 Source # | |
Round RoundHalfToZero Word8 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfToZero (n + k) Word8 -> Decimal RoundHalfToZero n Word8 Source # | |
Round RoundHalfToZero Integer Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfToZero (n + k) Integer -> Decimal RoundHalfToZero n Integer Source # | |
Round RoundHalfToZero Int Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfToZero (n + k) Int -> Decimal RoundHalfToZero n Int Source # | |
Round RoundHalfToZero Word Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfToZero (n + k) Word -> Decimal RoundHalfToZero n Word Source # | |
Round RoundHalfUp Int16 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfUp (n + k) Int16 -> Decimal RoundHalfUp n Int16 Source # | |
Round RoundHalfUp Int32 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfUp (n + k) Int32 -> Decimal RoundHalfUp n Int32 Source # | |
Round RoundHalfUp Int64 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfUp (n + k) Int64 -> Decimal RoundHalfUp n Int64 Source # | |
Round RoundHalfUp Int8 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfUp (n + k) Int8 -> Decimal RoundHalfUp n Int8 Source # | |
Round RoundHalfUp Word16 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfUp (n + k) Word16 -> Decimal RoundHalfUp n Word16 Source # | |
Round RoundHalfUp Word32 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfUp (n + k) Word32 -> Decimal RoundHalfUp n Word32 Source # | |
Round RoundHalfUp Word64 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfUp (n + k) Word64 -> Decimal RoundHalfUp n Word64 Source # | |
Round RoundHalfUp Word8 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfUp (n + k) Word8 -> Decimal RoundHalfUp n Word8 Source # | |
Round RoundHalfUp Integer Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfUp (n + k) Integer -> Decimal RoundHalfUp n Integer Source # | |
Round RoundHalfUp Int Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfUp (n + k) Int -> Decimal RoundHalfUp n Int Source # | |
Round RoundHalfUp Word Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfUp (n + k) Word -> Decimal RoundHalfUp n Word Source # | |
Round RoundToZero Int16 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundToZero (n + k) Int16 -> Decimal RoundToZero n Int16 Source # | |
Round RoundToZero Int32 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundToZero (n + k) Int32 -> Decimal RoundToZero n Int32 Source # | |
Round RoundToZero Int64 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundToZero (n + k) Int64 -> Decimal RoundToZero n Int64 Source # | |
Round RoundToZero Int8 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundToZero (n + k) Int8 -> Decimal RoundToZero n Int8 Source # | |
Round RoundToZero Word16 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundToZero (n + k) Word16 -> Decimal RoundToZero n Word16 Source # | |
Round RoundToZero Word32 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundToZero (n + k) Word32 -> Decimal RoundToZero n Word32 Source # | |
Round RoundToZero Word64 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundToZero (n + k) Word64 -> Decimal RoundToZero n Word64 Source # | |
Round RoundToZero Word8 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundToZero (n + k) Word8 -> Decimal RoundToZero n Word8 Source # | |
Round RoundToZero Integer Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundToZero (n + k) Integer -> Decimal RoundToZero n Integer Source # | |
Round RoundToZero Int Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundToZero (n + k) Int -> Decimal RoundToZero n Int Source # | |
Round RoundToZero Word Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundToZero (n + k) Word -> Decimal RoundToZero n Word Source # |
Rounding
Round half up
data RoundHalfUp Source #
Round half up rounding strategy:
>>>
:set -XDataKinds
>>>
roundDecimal <$> (3.740 :: Arith (Decimal RoundHalfUp 3 Int)) :: Arith (Decimal RoundHalfUp 1 Int)
Arith 3.7
Or with a bit more concise approach using arithRoundD
and TypeApplications
:
>>>
:set -XTypeApplications
>>>
arithRoundD @1 @RoundHalfUp @3 @Int 3.740
Arith 3.7>>>
arithRoundD @1 @RoundHalfUp @3 @Int 3.749
Arith 3.7>>>
arithRoundD @1 @RoundHalfUp @3 @Int 3.750
Arith 3.8>>>
arithRoundD @1 @RoundHalfUp @3 @Int 3.751
Arith 3.8>>>
arithRoundD @1 @RoundHalfUp @3 @Int 3.760
Arith 3.8>>>
arithRoundD @1 @RoundHalfUp @3 @Int (-3.740)
Arith -3.7>>>
arithRoundD @1 @RoundHalfUp @3 @Int (-3.749)
Arith -3.7>>>
arithRoundD @1 @RoundHalfUp @3 @Int (-3.750)
Arith -3.7>>>
arithRoundD @1 @RoundHalfUp @3 @Int (-3.751)
Arith -3.8>>>
arithRoundD @1 @RoundHalfUp @3 @Int (-3.760)
Arith -3.8
Since: 0.1.0
Instances
Round RoundHalfUp Int16 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfUp (n + k) Int16 -> Decimal RoundHalfUp n Int16 Source # | |
Round RoundHalfUp Int32 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfUp (n + k) Int32 -> Decimal RoundHalfUp n Int32 Source # | |
Round RoundHalfUp Int64 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfUp (n + k) Int64 -> Decimal RoundHalfUp n Int64 Source # | |
Round RoundHalfUp Int8 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfUp (n + k) Int8 -> Decimal RoundHalfUp n Int8 Source # | |
Round RoundHalfUp Word16 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfUp (n + k) Word16 -> Decimal RoundHalfUp n Word16 Source # | |
Round RoundHalfUp Word32 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfUp (n + k) Word32 -> Decimal RoundHalfUp n Word32 Source # | |
Round RoundHalfUp Word64 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfUp (n + k) Word64 -> Decimal RoundHalfUp n Word64 Source # | |
Round RoundHalfUp Word8 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfUp (n + k) Word8 -> Decimal RoundHalfUp n Word8 Source # | |
Round RoundHalfUp Integer Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfUp (n + k) Integer -> Decimal RoundHalfUp n Integer Source # | |
Round RoundHalfUp Int Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfUp (n + k) Int -> Decimal RoundHalfUp n Int Source # | |
Round RoundHalfUp Word Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfUp (n + k) Word -> Decimal RoundHalfUp n Word Source # |
roundHalfUp :: forall r (n :: Natural) (k :: Nat) p. (Integral p, KnownNat k) => Decimal r (n + k) p -> Decimal r n p Source #
Round half down
data RoundHalfDown Source #
Round half down rounding strategy:
>>>
:set -XDataKinds
>>>
:set -XTypeApplications
>>>
arithRoundD @1 @RoundHalfDown @3 @Int 3.740
Arith 3.7>>>
arithRoundD @1 @RoundHalfDown @3 @Int 3.749
Arith 3.7>>>
arithRoundD @1 @RoundHalfDown @3 @Int 3.750
Arith 3.7>>>
arithRoundD @1 @RoundHalfDown @3 @Int 3.751
Arith 3.8>>>
arithRoundD @1 @RoundHalfDown @3 @Int 3.760
Arith 3.8>>>
arithRoundD @1 @RoundHalfDown @3 @Int (-3.740)
Arith -3.7>>>
arithRoundD @1 @RoundHalfDown @3 @Int (-3.749)
Arith -3.7>>>
arithRoundD @1 @RoundHalfDown @3 @Int (-3.750)
Arith -3.8>>>
arithRoundD @1 @RoundHalfDown @3 @Int (-3.751)
Arith -3.8>>>
arithRoundD @1 @RoundHalfDown @3 @Int (-3.760)
Arith -3.8
Since: 0.2.0
Instances
Round RoundHalfDown Int16 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfDown (n + k) Int16 -> Decimal RoundHalfDown n Int16 Source # | |
Round RoundHalfDown Int32 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfDown (n + k) Int32 -> Decimal RoundHalfDown n Int32 Source # | |
Round RoundHalfDown Int64 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfDown (n + k) Int64 -> Decimal RoundHalfDown n Int64 Source # | |
Round RoundHalfDown Int8 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfDown (n + k) Int8 -> Decimal RoundHalfDown n Int8 Source # | |
Round RoundHalfDown Word16 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfDown (n + k) Word16 -> Decimal RoundHalfDown n Word16 Source # | |
Round RoundHalfDown Word32 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfDown (n + k) Word32 -> Decimal RoundHalfDown n Word32 Source # | |
Round RoundHalfDown Word64 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfDown (n + k) Word64 -> Decimal RoundHalfDown n Word64 Source # | |
Round RoundHalfDown Word8 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfDown (n + k) Word8 -> Decimal RoundHalfDown n Word8 Source # | |
Round RoundHalfDown Integer Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfDown (n + k) Integer -> Decimal RoundHalfDown n Integer Source # | |
Round RoundHalfDown Int Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfDown (n + k) Int -> Decimal RoundHalfDown n Int Source # | |
Round RoundHalfDown Word Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfDown (n + k) Word -> Decimal RoundHalfDown n Word Source # |
roundHalfDown :: forall r (n :: Natural) (k :: Nat) p. (Integral p, KnownNat k) => Decimal r (n + k) p -> Decimal r n p Source #
Round half even
data RoundHalfEven Source #
Round half even rounding
strategy. If the fractional part of x is 0.5, then y is the even integer nearest to
x. This is the default rounding strategy in Haskell implemented by round
.
>>>
:set -XDataKinds
>>>
:set -XTypeApplications
>>>
arithRoundD @1 @RoundHalfEven @3 @Int 3.650
Arith 3.6>>>
arithRoundD @1 @RoundHalfEven @3 @Int 3.740
Arith 3.7>>>
arithRoundD @1 @RoundHalfEven @3 @Int 3.749
Arith 3.7>>>
arithRoundD @1 @RoundHalfEven @3 @Int 3.750
Arith 3.8>>>
arithRoundD @1 @RoundHalfEven @3 @Int 3.751
Arith 3.8>>>
arithRoundD @1 @RoundHalfEven @3 @Int 3.760
Arith 3.8>>>
arithRoundD @1 @RoundHalfEven @3 @Int (-3.650)
Arith -3.6>>>
arithRoundD @1 @RoundHalfEven @3 @Int (-3.740)
Arith -3.7>>>
arithRoundD @1 @RoundHalfEven @3 @Int (-3.749)
Arith -3.7>>>
arithRoundD @1 @RoundHalfEven @3 @Int (-3.750)
Arith -3.8>>>
arithRoundD @1 @RoundHalfEven @3 @Int (-3.751)
Arith -3.8>>>
arithRoundD @1 @RoundHalfEven @3 @Int (-3.760)
Arith -3.8
Since: 0.2.0
Instances
Round RoundHalfEven Int16 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfEven (n + k) Int16 -> Decimal RoundHalfEven n Int16 Source # | |
Round RoundHalfEven Int32 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfEven (n + k) Int32 -> Decimal RoundHalfEven n Int32 Source # | |
Round RoundHalfEven Int64 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfEven (n + k) Int64 -> Decimal RoundHalfEven n Int64 Source # | |
Round RoundHalfEven Int8 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfEven (n + k) Int8 -> Decimal RoundHalfEven n Int8 Source # | |
Round RoundHalfEven Word16 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfEven (n + k) Word16 -> Decimal RoundHalfEven n Word16 Source # | |
Round RoundHalfEven Word32 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfEven (n + k) Word32 -> Decimal RoundHalfEven n Word32 Source # | |
Round RoundHalfEven Word64 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfEven (n + k) Word64 -> Decimal RoundHalfEven n Word64 Source # | |
Round RoundHalfEven Word8 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfEven (n + k) Word8 -> Decimal RoundHalfEven n Word8 Source # | |
Round RoundHalfEven Integer Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfEven (n + k) Integer -> Decimal RoundHalfEven n Integer Source # | |
Round RoundHalfEven Int Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfEven (n + k) Int -> Decimal RoundHalfEven n Int Source # | |
Round RoundHalfEven Word Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfEven (n + k) Word -> Decimal RoundHalfEven n Word Source # |
roundHalfEven :: forall r (n :: Natural) (k :: Nat) p. (Integral p, KnownNat k) => Decimal r (n + k) p -> Decimal r n p Source #
Round half to zero
data RoundHalfToZero Source #
Round half towards zero rounding strategy. If the fraction of x is exactly 0.5, then y = x − 0.5 if x is positive, and y = x + 0.5 if x is negative.
>>>
:set -XDataKinds
>>>
:set -XTypeApplications
>>>
arithRoundD @1 @RoundHalfToZero @3 @Int 3.650
Arith 3.6>>>
arithRoundD @1 @RoundHalfToZero @3 @Int 3.740
Arith 3.7>>>
arithRoundD @1 @RoundHalfToZero @4 @Int 3.7501
Arith 3.8>>>
arithRoundD @1 @RoundHalfToZero @3 @Int (-3.650)
Arith -3.6>>>
arithRoundD @1 @RoundHalfToZero @3 @Int (-3.740)
Arith -3.7>>>
arithRoundD @1 @RoundHalfToZero @4 @Int (-3.7501)
Arith -3.8>>>
arithRoundD @1 @RoundHalfToZero @3 @Int (-3.760)
Arith -3.8
Instances
Round RoundHalfToZero Int16 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfToZero (n + k) Int16 -> Decimal RoundHalfToZero n Int16 Source # | |
Round RoundHalfToZero Int32 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfToZero (n + k) Int32 -> Decimal RoundHalfToZero n Int32 Source # | |
Round RoundHalfToZero Int64 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfToZero (n + k) Int64 -> Decimal RoundHalfToZero n Int64 Source # | |
Round RoundHalfToZero Int8 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfToZero (n + k) Int8 -> Decimal RoundHalfToZero n Int8 Source # | |
Round RoundHalfToZero Word16 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfToZero (n + k) Word16 -> Decimal RoundHalfToZero n Word16 Source # | |
Round RoundHalfToZero Word32 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfToZero (n + k) Word32 -> Decimal RoundHalfToZero n Word32 Source # | |
Round RoundHalfToZero Word64 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfToZero (n + k) Word64 -> Decimal RoundHalfToZero n Word64 Source # | |
Round RoundHalfToZero Word8 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfToZero (n + k) Word8 -> Decimal RoundHalfToZero n Word8 Source # | |
Round RoundHalfToZero Integer Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfToZero (n + k) Integer -> Decimal RoundHalfToZero n Integer Source # | |
Round RoundHalfToZero Int Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfToZero (n + k) Int -> Decimal RoundHalfToZero n Int Source # | |
Round RoundHalfToZero Word Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfToZero (n + k) Word -> Decimal RoundHalfToZero n Word Source # |
roundHalfToZero :: forall r (n :: Natural) (k :: Nat) p. (Integral p, KnownNat k) => Decimal r (n + k) p -> Decimal r n p Source #
Round half from zero
data RoundHalfFromZero Source #
Round half away from zero rounding strategy. If the fraction of x is exactly 0.5, then y = x + 0.5 if x is positive, and y = x − 0.5 if x is negative.
>>>
:set -XDataKinds
>>>
:set -XTypeApplications
>>>
arithRoundD @1 @RoundHalfFromZero @3 @Int 3.650
Arith 3.7>>>
arithRoundD @1 @RoundHalfFromZero @3 @Int 3.740
Arith 3.7>>>
arithRoundD @1 @RoundHalfFromZero @3 @Int 3.751
Arith 3.8>>>
arithRoundD @1 @RoundHalfFromZero @3 @Int (-3.650)
Arith -3.7>>>
arithRoundD @1 @RoundHalfFromZero @3 @Int (-3.740)
Arith -3.7>>>
arithRoundD @1 @RoundHalfFromZero @3 @Int (-3.751)
Arith -3.8>>>
arithRoundD @1 @RoundHalfFromZero @3 @Int (-3.760)
Arith -3.8
Instances
Round RoundHalfFromZero Int16 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfFromZero (n + k) Int16 -> Decimal RoundHalfFromZero n Int16 Source # | |
Round RoundHalfFromZero Int32 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfFromZero (n + k) Int32 -> Decimal RoundHalfFromZero n Int32 Source # | |
Round RoundHalfFromZero Int64 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfFromZero (n + k) Int64 -> Decimal RoundHalfFromZero n Int64 Source # | |
Round RoundHalfFromZero Int8 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfFromZero (n + k) Int8 -> Decimal RoundHalfFromZero n Int8 Source # | |
Round RoundHalfFromZero Word16 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfFromZero (n + k) Word16 -> Decimal RoundHalfFromZero n Word16 Source # | |
Round RoundHalfFromZero Word32 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfFromZero (n + k) Word32 -> Decimal RoundHalfFromZero n Word32 Source # | |
Round RoundHalfFromZero Word64 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfFromZero (n + k) Word64 -> Decimal RoundHalfFromZero n Word64 Source # | |
Round RoundHalfFromZero Word8 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfFromZero (n + k) Word8 -> Decimal RoundHalfFromZero n Word8 Source # | |
Round RoundHalfFromZero Integer Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfFromZero (n + k) Integer -> Decimal RoundHalfFromZero n Integer Source # | |
Round RoundHalfFromZero Int Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfFromZero (n + k) Int -> Decimal RoundHalfFromZero n Int Source # | |
Round RoundHalfFromZero Word Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundHalfFromZero (n + k) Word -> Decimal RoundHalfFromZero n Word Source # |
roundHalfFromZero :: forall r (n :: Natural) (k :: Nat) p. (Integral p, KnownNat k) => Decimal r (n + k) p -> Decimal r n p Source #
Round down
Round down rounding
startegy. This the strategy that is implemented by floor
. Round towards minus
infinity:
>>>
:set -XDataKinds
>>>
:set -XTypeApplications
>>>
arithRoundD @1 @RoundDown @2 @Int 3.65
Arith 3.6>>>
arithRoundD @1 @RoundDown @2 @Int 3.75
Arith 3.7>>>
arithRoundD @1 @RoundDown @2 @Int 3.89
Arith 3.8>>>
arithRoundD @1 @RoundDown @2 @Int (-3.65)
Arith -3.7
Since: 0.2.0
Instances
Round RoundDown Int16 Source # | |
Round RoundDown Int32 Source # | |
Round RoundDown Int64 Source # | |
Round RoundDown Int8 Source # | |
Round RoundDown Word16 Source # | |
Round RoundDown Word32 Source # | |
Round RoundDown Word64 Source # | |
Round RoundDown Word8 Source # | |
Round RoundDown Integer Source # | |
Round RoundDown Int Source # | |
Round RoundDown Word Source # | |
roundDown :: forall r (n :: Natural) (k :: Nat) p. (Integral p, KnownNat k) => Decimal r (n + k) p -> Decimal r n p Source #
Round towards zero
data RoundToZero Source #
Round towards zero strategy. Similar to Haskell's truncate
. Drop the fractional digits, regardless of
the sign.
>>>
:set -XDataKinds
>>>
:set -XTypeApplications
>>>
arithRoundD @1 @RoundToZero @2 @Int 3.65
Arith 3.6>>>
arithRoundD @1 @RoundToZero @2 @Int 3.75
Arith 3.7>>>
arithRoundD @1 @RoundToZero @2 @Int 3.89
Arith 3.8>>>
arithRoundD @1 @RoundToZero @2 @Int (-3.65)
Arith -3.6
Since: 0.2.0
Instances
Round RoundToZero Int16 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundToZero (n + k) Int16 -> Decimal RoundToZero n Int16 Source # | |
Round RoundToZero Int32 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundToZero (n + k) Int32 -> Decimal RoundToZero n Int32 Source # | |
Round RoundToZero Int64 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundToZero (n + k) Int64 -> Decimal RoundToZero n Int64 Source # | |
Round RoundToZero Int8 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundToZero (n + k) Int8 -> Decimal RoundToZero n Int8 Source # | |
Round RoundToZero Word16 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundToZero (n + k) Word16 -> Decimal RoundToZero n Word16 Source # | |
Round RoundToZero Word32 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundToZero (n + k) Word32 -> Decimal RoundToZero n Word32 Source # | |
Round RoundToZero Word64 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundToZero (n + k) Word64 -> Decimal RoundToZero n Word64 Source # | |
Round RoundToZero Word8 Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundToZero (n + k) Word8 -> Decimal RoundToZero n Word8 Source # | |
Round RoundToZero Integer Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundToZero (n + k) Integer -> Decimal RoundToZero n Integer Source # | |
Round RoundToZero Int Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundToZero (n + k) Int -> Decimal RoundToZero n Int Source # | |
Round RoundToZero Word Source # | |
Defined in Numeric.Decimal Methods roundDecimal :: forall (k :: Nat) (n :: Natural). KnownNat k => Decimal RoundToZero (n + k) Word -> Decimal RoundToZero n Word Source # |
type Truncate = RoundToZero Source #
Synonym for RoundToZero
Since: 0.1.0
roundToZero :: forall r (n :: Natural) (k :: Nat) p. (Integral p, KnownNat k) => Decimal r (n + k) p -> Decimal r n p Source #
Operations
decimalList :: forall p r (s :: Nat). Integral p => [p] -> [Decimal r s p] Source #
O(1) - Conversion of a list.
Note: It doesn't do any scaling, eg:
>>>
:set -XDataKinds
>>>
import Numeric.Decimal
>>>
decimalList [1,20,300] :: [Decimal RoundHalfUp 2 Int]
[0.01,0.20,3.00]
If scaling is what you need use fromIntegral
instead:
>>>
sequenceA [1, 20, 300] :: Arith [Decimal RoundHalfUp 2 Int]
Arith [1.00,20.00,300.00]
Since: 0.1.0
sumDecimalBounded :: forall m f p r (s :: Nat). (MonadThrow m, Foldable f, Eq p, Ord p, Num p, Bounded p) => f (Decimal r s p) -> m (Decimal r s p) Source #
Sum a list of decimal numbers
>>>
:set -XDataKinds
>>>
sequenceA [1.1, 20.02, 300.003] >>= sumDecimalBounded :: Arith (Decimal RoundHalfUp 3 Int)
Arith 321.123
Since: 0.2.0
productDecimalBoundedWithRounding :: forall m f (s :: Nat) r p. (MonadThrow m, Foldable f, KnownNat s, Round r Integer, Integral p, Bounded p) => f (Decimal r s p) -> m (Decimal r s p) Source #
Multiply all decimal numbers in the list while doing rounding.
>>>
:set -XDataKinds
>>>
product [1.1, 20.02, 300.003] :: Double
6606.666066000001>>>
xs <- arithM (mapM fromRational [1.1, 20.02, 300.003] :: Arith [Decimal RoundHalfUp 4 Int])
>>>
xs
[1.1000,20.0200,300.0030]>>>
productDecimalBoundedWithRounding xs
6606.6661
Since: 0.2.0
Conversion
Fixed
type family FixedScale e :: Nat Source #
Instances
type FixedScale E0 Source # | |
Defined in Numeric.Decimal | |
type FixedScale E1 Source # | |
Defined in Numeric.Decimal | |
type FixedScale E12 Source # | |
Defined in Numeric.Decimal | |
type FixedScale E2 Source # | |
Defined in Numeric.Decimal | |
type FixedScale E3 Source # | |
Defined in Numeric.Decimal | |
type FixedScale E6 Source # | |
Defined in Numeric.Decimal | |
type FixedScale E9 Source # | |
Defined in Numeric.Decimal |
toFixedDecimal :: forall (s :: Nat) e p r. (s ~ FixedScale e, Integral p) => Decimal r s p -> Fixed e Source #
fromFixedDecimal :: forall (s :: Nat) e r. s ~ FixedScale e => Fixed e -> Decimal r s Integer Source #
fromFixedDecimalBounded :: forall (s :: Nat) e m p r. (s ~ FixedScale e, MonadThrow m, Integral p, Bounded p) => Fixed e -> m (Decimal r s p) Source #
Convert a Fixed
to a decimal backed by a bounded integral with the exactly same
precision
>>>
fromFixedDecimalBounded (123.458 :: Fixed E3) :: Arith (Decimal RoundToZero 3 Int)
Arith 123.458>>>
fromFixedDecimalBounded (123.458 :: Fixed E3) :: Arith (Decimal RoundToZero 3 Int8)
ArithError arithmetic overflow>>>
fromFixedDecimalBounded (-123.458 :: Fixed E3) :: Arith (Decimal RoundToZero 3 Word)
ArithError arithmetic underflow
Since: 0.2.0
Scientific
toScientificDecimal :: forall p (s :: Nat) r. (Integral p, KnownNat s) => Decimal r s p -> Scientific Source #
Convert a Decimal
to Scientific
Since: 0.1.0
fromScientificDecimal :: forall m r (s :: Nat). (MonadThrow m, KnownNat s) => Scientific -> m (Decimal r s Integer) Source #
Convert Scientific to Decimal without loss of precision. Will return Left
Underflow
if
Scientific
has too many decimal places, more than Decimal
scaling is capable to handle.
Since: 0.1.0
fromScientificDecimalBounded :: forall m r (s :: Nat) p. (MonadThrow m, Integral p, Bounded p, KnownNat s) => Scientific -> m (Decimal r s p) Source #
Convert from Scientific to bounded Decimal while checking for Overflow/Underflow
Since: 0.1.0