Safe Haskell | None |
---|---|
Language | Haskell2010 |
- newtype CReal n = CR (Int -> Integer)
- atPrecision :: CReal n -> Int -> Integer
- crealPrecision :: KnownNat n => CReal n -> Int
- shiftL :: CReal n -> Int -> CReal n
- shiftR :: CReal n -> Int -> CReal n
- (/.) :: Integer -> Integer -> Integer
- log2 :: Integer -> Int
- log10 :: Integer -> Int
- decimalDigitsAtPrecision :: Int -> Int
- rationalToDecimal :: Int -> Rational -> String
Documentation
The type CReal represents a fast binary Cauchy sequence. This is a Cauchy sequence with the property that the pth element will be within 2^-p of the true value. Internally this sequence is represented as a function from Ints to Integers.
KnownNat n => Eq (CReal n) Source | Values of type
|
Fractional (CReal n) Source | Taking the reciprocal of zero will not terminate |
Num (CReal n) Source |
This is a little bit of a fudge, but it's probably better than failing to terminate when trying to find the sign of zero. The class still respects the abs-signum law though.
|
KnownNat n => Ord (CReal n) Source | Like equality values of type |
KnownNat n => Show (CReal n) Source | A CReal with precision p is shown as a decimal number d such that d is within 2^-p of the true value.
|
atPrecision :: CReal n -> Int -> Integer Source
x `atPrecision` p
returns the numerator of the pth element in the
Cauchy sequence represented by x. The denominator is 2^p.
>>>
10 `atPrecision` 10
10240
crealPrecision :: KnownNat n => CReal n -> Int Source
crealPrecision x returns the type level parameter representing x's default precision.
>>>
crealPrecision (1 :: CReal 10)
10
shiftL :: CReal n -> Int -> CReal n Source
x `shiftL` n
is equal to x
multiplied by 2^n
n
can be negative or zero
This can be faster than doing the multiplication
shiftR :: CReal n -> Int -> CReal n Source
x `shiftR` n
is equal to x
divided by 2^n
n
can be negative or zero
This can be faster than doing the division
(/.) :: Integer -> Integer -> Integer infixl 7 Source
Division rounding to the nearest integer and rounding half integers to the nearest even integer.
decimalDigitsAtPrecision :: Int -> Int Source
How many decimal digits are required to represent a number to within 2^-p
rationalToDecimal :: Int -> Rational -> String Source
rationalToDecimal p x
returns a string representing x
at p
decimal
places.