License | MIT |
---|---|
Maintainer | douglas.mcclean@gmail.com |
Stability | experimental |
Safe Haskell | Safe |
Language | Haskell2010 |
Extensions |
|
This type is sufficient to exactly express the closure of Q ∪ {π} under multiplication and division.
As a result it is useful for representing conversion factors
between physical units. Approximate values are included both to close the remainder
of the arithmetic operations in the Num
typeclass and to encode conversion
factors defined experimentally.
- 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.
approximateValue :: Floating a => ExactPi -> a Source
isZero :: ExactPi -> Bool Source
Identifies whether an ExactPi
is an exact or approximate representation of zero.
isExactZero :: ExactPi -> Bool Source
Identifies whether an ExactPi
is an exact representation of zero.
isExactOne :: ExactPi -> Bool Source
Identifies whether an ExactPi
is an exact representation of one.
areExactlyEqual :: ExactPi -> ExactPi -> Bool Source
Identifies whether two ExactPi
values are exactly equal.
isExactInteger :: ExactPi -> Bool Source
Identifies whether an ExactPi
is an exact representation of an integer.
toExactInteger :: ExactPi -> Maybe Integer Source
isExactRational :: ExactPi -> Bool Source
Identifies whether an ExactPi
is an exact representation of a rational.
rationalApproximations :: ExactPi -> [Rational] Source
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.