Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Synopsis
- data ExactPi
- = Exact Integer Rational
- | Approximate (forall a. Floating a => a)
- approximateValue :: Floating a => ExactPi -> a
- isZero :: ExactPi -> Bool
- isExact :: ExactPi -> Bool
- isExactZero :: ExactPi -> Bool
- isExactOne :: ExactPi -> Bool
- areExactlyEqual :: ExactPi -> ExactPi -> Bool
- isExactInteger :: ExactPi -> Bool
- toExactInteger :: ExactPi -> Maybe Integer
- isExactRational :: ExactPi -> Bool
- toExactRational :: ExactPi -> Maybe Rational
- rationalApproximations :: ExactPi -> [Rational]
Documentation
Represents an exact or approximate real value. The exactly representable values are rational multiples of an integer power of pi.
Exact Integer Rational |
|
Approximate (forall a. Floating a => a) | An approximate value. This representation was chosen because it allows conversion to floating types using their native definition of |
Instances
Floating ExactPi | |
Fractional ExactPi | |
Num ExactPi | |
Show ExactPi | |
Semigroup ExactPi | The multiplicative semigroup over |
Monoid ExactPi | The multiplicative monoid over |
approximateValue :: Floating a => ExactPi -> a #
Identifies whether an ExactPi
is an exact or approximate representation of zero.
isExactZero :: ExactPi -> Bool #
Identifies whether an ExactPi
is an exact representation of zero.
isExactOne :: ExactPi -> Bool #
Identifies whether an ExactPi
is an exact representation of one.
areExactlyEqual :: ExactPi -> ExactPi -> Bool #
Identifies whether two ExactPi
values are exactly equal.
isExactInteger :: ExactPi -> Bool #
Identifies whether an ExactPi
is an exact representation of an integer.
isExactRational :: ExactPi -> Bool #
Identifies whether an ExactPi
is an exact representation of a rational.
rationalApproximations :: ExactPi -> [Rational] #
Converts an ExactPi
to a list of increasingly accurate rational approximations, on alternating
sides of the actual value. Note that Approximate
values are converted using the Real
instance
for Double
into a singleton list. Note that exact rationals are also converted into a singleton list.
Implementation based on work by Anders Kaseorg shared at http://qr.ae/RbXl8M.