module Factory.Math.Implementations.Pi.Spigot.Algorithm(
Algorithm(..)
) where
import qualified Data.Default
import Data.Ratio((%))
import qualified Factory.Math.Implementations.Pi.Spigot.Gosper as Math.Implementations.Pi.Spigot.Gosper
import qualified Factory.Math.Implementations.Pi.Spigot.RabinowitzWagon as Math.Implementations.Pi.Spigot.RabinowitzWagon
import qualified Factory.Math.Implementations.Pi.Spigot.Spigot as Math.Implementations.Pi.Spigot.Spigot
import qualified Factory.Math.Pi as Math.Pi
data Algorithm
= Gosper
| RabinowitzWagon
deriving (Algorithm -> Algorithm -> Bool
(Algorithm -> Algorithm -> Bool)
-> (Algorithm -> Algorithm -> Bool) -> Eq Algorithm
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Algorithm -> Algorithm -> Bool
$c/= :: Algorithm -> Algorithm -> Bool
== :: Algorithm -> Algorithm -> Bool
$c== :: Algorithm -> Algorithm -> Bool
Eq, ReadPrec [Algorithm]
ReadPrec Algorithm
Int -> ReadS Algorithm
ReadS [Algorithm]
(Int -> ReadS Algorithm)
-> ReadS [Algorithm]
-> ReadPrec Algorithm
-> ReadPrec [Algorithm]
-> Read Algorithm
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Algorithm]
$creadListPrec :: ReadPrec [Algorithm]
readPrec :: ReadPrec Algorithm
$creadPrec :: ReadPrec Algorithm
readList :: ReadS [Algorithm]
$creadList :: ReadS [Algorithm]
readsPrec :: Int -> ReadS Algorithm
$creadsPrec :: Int -> ReadS Algorithm
Read, Int -> Algorithm -> ShowS
[Algorithm] -> ShowS
Algorithm -> String
(Int -> Algorithm -> ShowS)
-> (Algorithm -> String)
-> ([Algorithm] -> ShowS)
-> Show Algorithm
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Algorithm] -> ShowS
$cshowList :: [Algorithm] -> ShowS
show :: Algorithm -> String
$cshow :: Algorithm -> String
showsPrec :: Int -> Algorithm -> ShowS
$cshowsPrec :: Int -> Algorithm -> ShowS
Show)
instance Data.Default.Default Algorithm where
def :: Algorithm
def = Algorithm
Gosper
instance Math.Pi.Algorithmic Algorithm where
openI :: Algorithm -> Int -> Integer
openI Algorithm
Gosper = Series Int -> Int -> Integer
Math.Implementations.Pi.Spigot.Spigot.openI Series Int
forall i. Integral i => Series i
Math.Implementations.Pi.Spigot.Gosper.series
openI Algorithm
RabinowitzWagon = Series Int -> Int -> Integer
Math.Implementations.Pi.Spigot.Spigot.openI Series Int
forall i. Integral i => Series i
Math.Implementations.Pi.Spigot.RabinowitzWagon.series
openR :: Algorithm -> Int -> Rational
openR Algorithm
algorithm Int
decimalDigits = Algorithm -> Int -> Integer
forall algorithm.
Algorithmic algorithm =>
algorithm -> Int -> Integer
Math.Pi.openI Algorithm
algorithm Int
decimalDigits Integer -> Integer -> Rational
forall a. Integral a => a -> a -> Ratio a
% (Integer
10 Integer -> Int -> Integer
forall a b. (Num a, Integral b) => a -> b -> a
^ Int -> Int
forall a. Enum a => a -> a
pred Int
decimalDigits)