planet-mitchell-0.1.0: Planet Mitchell

Safe HaskellSafe
LanguageHaskell2010

Num.Pi

Synopsis

Documentation

data ExactPi #

Represents an exact or approximate real value. The exactly representable values are rational multiples of an integer power of pi.

Constructors

Exact Integer Rational

Exact z q = q * pi^z. Note that this means there are many representations of zero.

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 pi.

Instances
Floating ExactPi 
Instance details

Defined in Data.ExactPi

Fractional ExactPi 
Instance details

Defined in Data.ExactPi

Num ExactPi 
Instance details

Defined in Data.ExactPi

Show ExactPi 
Instance details

Defined in Data.ExactPi

Semigroup ExactPi

The multiplicative semigroup over Rationals augmented with multiples of pi.

Instance details

Defined in Data.ExactPi

Monoid ExactPi

The multiplicative monoid over Rationals augmented with multiples of pi.

Instance details

Defined in Data.ExactPi

approximateValue :: Floating a => ExactPi -> a #

Approximates an exact or approximate value, converting it to a Floating type. This uses the value of pi supplied by the destination type, to provide the appropriate precision.

isZero :: ExactPi -> Bool #

Identifies whether an ExactPi is an exact or approximate representation of zero.

isExact :: ExactPi -> Bool #

Identifies whether an ExactPi is an exact value.

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.

toExactInteger :: ExactPi -> Maybe Integer #

Converts an ExactPi to an exact Integer or Nothing.

isExactRational :: ExactPi -> Bool #

Identifies whether an ExactPi is an exact representation of a rational.

toExactRational :: ExactPi -> Maybe Rational #

Converts an ExactPi to an exact Rational or Nothing.

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.