Copyright | (C) Frank Staals |
---|---|
License | see the LICENSE file |
Maintainer | Frank Staals |
Safe Haskell | None |
Language | GHC2021 |
Synopsis
- newtype RealNumber (p :: Nat) = RealNumber Rational
- data AsFixed (p :: k)
- asFixed :: forall (p :: Nat). KnownNat p => RealNumber p -> AsFixed (NatPrec p)
- toFixed :: forall (p :: Nat). KnownNat p => RealNumber p -> Fixed (NatPrec p)
- fromFixed :: forall (p :: Nat). KnownNat p => Fixed (NatPrec p) -> RealNumber p
- type Nat = Natural
Documentation
newtype RealNumber (p :: Nat) Source #
Real Numbers represented using Rational numbers. The number type itself is exact in the sense that we can represent any rational number.
The parameter, a natural number, represents the precision (in number of decimals behind the period) with which we display the numbers when printing them (using Show).
If the number cannot be displayed exactly a ~
is printed after
the number.
Instances
Converting to and from RealNumber's
data AsFixed (p :: k) Source #
Fixed-precision representation of a RealNumber
. If there's insufficient
precision to accurately represent the RealNumber
then the Lossy
constructor
will be used.
asFixed :: forall (p :: Nat). KnownNat p => RealNumber p -> AsFixed (NatPrec p) Source #
Cast RealNumber
to a fixed-precision number. Data-loss caused by insufficient
precision will be marked by the Lossy
constructor.
toFixed :: forall (p :: Nat). KnownNat p => RealNumber p -> Fixed (NatPrec p) Source #
Cast RealNumber
to a fixed-precision number. Data is silently lost if there's
insufficient precision.
fromFixed :: forall (p :: Nat). KnownNat p => Fixed (NatPrec p) -> RealNumber p Source #
Cast a fixed-precision number to a RealNumber
.