exact-real-0.2.1.0: Exact real arithmetic

Safe HaskellNone
LanguageHaskell2010

Data.CReal

Synopsis

Documentation

data CReal n Source

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.

Instances

KnownNat n => Eq (CReal n) Source

Values of type CReal p are compared for equality at precision p. This may cause values which differ by less than 2^-p to compare as equal.

>>> 0 == (0.1 :: CReal 1)
True

Methods

(==) :: CReal n -> CReal n -> Bool

(/=) :: CReal n -> CReal n -> Bool

Fractional (CReal n) Source

Taking the reciprocal of zero will not terminate

Methods

(/) :: CReal n -> CReal n -> CReal n

recip :: CReal n -> CReal n

fromRational :: Rational -> CReal n

Num (CReal n) Source

signum (x :: CReal p) returns the sign of x at precision p. It's important to remember that this may not represent the actual sign of x if the distance between x and zero is less than 2^-p.

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.

>>> signum (0.1 :: CReal 2)
0.0
>>> signum (0.1 :: CReal 3)
1.0

Methods

(+) :: CReal n -> CReal n -> CReal n

(-) :: CReal n -> CReal n -> CReal n

(*) :: CReal n -> CReal n -> CReal n

negate :: CReal n -> CReal n

abs :: CReal n -> CReal n

signum :: CReal n -> CReal n

fromInteger :: Integer -> CReal n

KnownNat n => Ord (CReal n) Source

Like equality values of type CReal p are compared at precision p.

Methods

compare :: CReal n -> CReal n -> Ordering

(<) :: CReal n -> CReal n -> Bool

(<=) :: CReal n -> CReal n -> Bool

(>) :: CReal n -> CReal n -> Bool

(>=) :: CReal n -> CReal n -> Bool

max :: CReal n -> CReal n -> CReal n

min :: CReal n -> CReal n -> CReal n

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.

>>> show (47176870 :: CReal 0)
"47176870"

Methods

showsPrec :: Int -> CReal n -> ShowS

show :: CReal n -> String

showList :: [CReal n] -> ShowS

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