Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- newtype FixedDecimal (exp :: Natural) = FixedDecimal {}
- fixedNumerator :: forall (exp :: Natural). FixedDecimal exp -> Integer
- fixedDenominator :: forall (exp :: Natural). KnownNat exp => FixedDecimal exp -> Integer
- emul :: forall (expA :: Natural) (expB :: Natural). FixedDecimal expA -> FixedDecimal expB -> FixedDecimal (expA + expB)
- ediv :: forall (expA :: Natural) (expB :: Natural). FixedDecimal expA -> FixedDecimal expB -> FixedDecimal (expA - expB)
- toFixedZero :: Integer -> FixedDecimal 0
- fromFixedZero :: FixedDecimal 0 -> Integer
- convertExp :: forall (expA :: Natural) (expB :: Natural). (KnownNat expA, KnownNat expB) => FixedDecimal expA -> FixedDecimal expB
- newtype PFixedDecimal (exp :: Natural) (s :: S) = PFixedDecimal (Term s PInteger)
- pfixedNumerator :: forall (s :: S) (unit :: Natural). Term s (PFixedDecimal unit) -> Term s PInteger
- pfixedDenominator :: forall (s :: S) (unit :: Natural). KnownNat unit => Term s (PFixedDecimal unit) -> Term s PInteger
- pemul :: forall (s :: S) (expA :: Natural) (expB :: Natural). Term s (PFixedDecimal expA) -> Term s (PFixedDecimal expB) -> Term s (PFixedDecimal (expA + expB))
- pediv :: forall (s :: S) (expA :: Natural) (expB :: Natural). Term s (PFixedDecimal expA) -> Term s (PFixedDecimal expB) -> Term s (PFixedDecimal (expA - expB))
- ptoFixedZero :: forall (s :: S). Term s PInteger -> Term s (PFixedDecimal 0)
- pfromFixedZero :: forall (s :: S). Term s (PFixedDecimal 0) -> Term s PInteger
- pconvertExp :: forall (exp2 :: Natural) (exp1 :: Natural) (s :: S). (KnownNat exp1, KnownNat exp2) => Term s (PFixedDecimal exp1 :--> PFixedDecimal exp2)
- pfromFixedDecimal :: forall (exp :: Natural) (s :: S). KnownNat exp => Term s (PFixedDecimal exp :--> PInteger)
- ptoFixedDecimal :: forall (exp :: Natural) (s :: S). KnownNat exp => Term s (PInteger :--> PFixedDecimal exp)
- ptoRational :: forall (exp :: Natural) (s :: S). KnownNat exp => Term s (PFixedDecimal exp :--> PRational)
- punsafeMkFixedDecimal :: forall (exp :: Natural) (s :: S). Term s (PInteger :--> PFixedDecimal exp)
Documentation
newtype FixedDecimal (exp :: Natural) Source #
Fixed precision number. It behaves like scientific notation:
exp
shows to what power of base 10 an integer is multiplied.
For example, Underlying value of 123456 with type `FixedDecimal 3` is
`123.456 (123456 * 10 ^ -3)`. If it's coerced into `FixedDecimal 5`, it will be
`1.23456 (123456 * 10 ^ -5)`. `FixedDecimal 0` will be identical to Integer
.
Note, exp
is the negative exponent to base 10.
Compared to Rational
, Fixed
gives addition and subtraction
as fast as regular PInteger
, allows negative values, and does
not require simplifications.
Performance note: Prefer emul
, ediv
, toFixedZero
, and
fromFixedZero
. Then group calculations in a way that requires the least
amount of convertExp
calls.
Since: 3.12.0
Instances
fixedNumerator :: forall (exp :: Natural). FixedDecimal exp -> Integer Source #
Integer numerator of FixedDecimal
Since: 3.12.0
fixedDenominator :: forall (exp :: Natural). KnownNat exp => FixedDecimal exp -> Integer Source #
Integer denominator of FixedDecimal
Since: 3.12.0
emul :: forall (expA :: Natural) (expB :: Natural). FixedDecimal expA -> FixedDecimal expB -> FixedDecimal (expA + expB) Source #
Exponent-changing multiplication (implemented with a single integer multiplication)
Since: 3.12.0
ediv :: forall (expA :: Natural) (expB :: Natural). FixedDecimal expA -> FixedDecimal expB -> FixedDecimal (expA - expB) Source #
Exponent-changing division (implemented with a single integer division)
Since: 3.12.0
toFixedZero :: Integer -> FixedDecimal 0 Source #
fromFixedZero :: FixedDecimal 0 -> Integer Source #
convertExp :: forall (expA :: Natural) (expB :: Natural). (KnownNat expA, KnownNat expB) => FixedDecimal expA -> FixedDecimal expB Source #
Convert to a different type-level exponent.
Since: 3.12.0
newtype PFixedDecimal (exp :: Natural) (s :: S) Source #
Fixed precision number. It behaves like scientific notation:
exp
shows to what power of base 10 an integer is multiplied.
For example, Underlying value of 123456 with type `PFixedDecimal 3` is
`123.456 (123456 * 10 ^ -3)`. If it's coerced into `PFixedDecimal 5`, it will be
`1.23456 (123456 * 10 ^ -5)`. `PFixedDecimal 0` will be identical to PInteger
.
Note, exp
is the negative exponent to base 10. PFixed
does not support
positive exponent.
Compared to PRational
, PFixed
gives addition and subtraction
as fast as regular PInteger
, allows negative values, and does
not require simplifications.
Performance note: Prefer pemul
, pediv
, ptoFixedZero
, and
pfromFixedZero
. Then group calculations in a way that requires the least
amount of convertExp
calls.
Since: 3.12.0
Instances
pfixedNumerator :: forall (s :: S) (unit :: Natural). Term s (PFixedDecimal unit) -> Term s PInteger Source #
Integer numerator of PFixedDecimal
Since: 3.12.0
pfixedDenominator :: forall (s :: S) (unit :: Natural). KnownNat unit => Term s (PFixedDecimal unit) -> Term s PInteger Source #
Integer denominator of PFixedDecimal
Since: 3.12.0
pemul :: forall (s :: S) (expA :: Natural) (expB :: Natural). Term s (PFixedDecimal expA) -> Term s (PFixedDecimal expB) -> Term s (PFixedDecimal (expA + expB)) Source #
Exponent-changing multiplication (implemented with a single integer multiplication)
Since: 3.12.0
pediv :: forall (s :: S) (expA :: Natural) (expB :: Natural). Term s (PFixedDecimal expA) -> Term s (PFixedDecimal expB) -> Term s (PFixedDecimal (expA - expB)) Source #
Exponent-changing division (implemented with a single integer division)
Since: 3.12.0
ptoFixedZero :: forall (s :: S). Term s PInteger -> Term s (PFixedDecimal 0) Source #
pfromFixedZero :: forall (s :: S). Term s (PFixedDecimal 0) -> Term s PInteger Source #
pconvertExp :: forall (exp2 :: Natural) (exp1 :: Natural) (s :: S). (KnownNat exp1, KnownNat exp2) => Term s (PFixedDecimal exp1 :--> PFixedDecimal exp2) Source #
Change decimal point.
- Caution* This function will drop precision when converting from more decimal points to less decimal points.
For example, converting `1.234 :: Fixed 3` into `Fixed 1` will drop hundredth and thousandth place value and will give `1.2 :: Fixed 1`.
There is not data loss going from small decimal points to big decimal points, but they will take up more memory.
Since: 3.12.0
pfromFixedDecimal :: forall (exp :: Natural) (s :: S). KnownNat exp => Term s (PFixedDecimal exp :--> PInteger) Source #
ptoFixedDecimal :: forall (exp :: Natural) (s :: S). KnownNat exp => Term s (PInteger :--> PFixedDecimal exp) Source #
ptoRational :: forall (exp :: Natural) (s :: S). KnownNat exp => Term s (PFixedDecimal exp :--> PRational) Source #