Move constants

This commit is contained in:
rnhmjoj 2015-06-01 17:17:22 +02:00
parent 81b04dc6fa
commit 628741482b
2 changed files with 22 additions and 20 deletions

View File

@ -5,6 +5,7 @@ import Data.Number.Types
import Data.Number.Instances
import Data.Number.Internal
-- Various --
precision :: Number -> Nat
@ -17,6 +18,7 @@ show' (x:|E) = show (toInteger x)
show' (x:|xs) = show (toInteger x) ++ " + 1/(" ++ show' xs ++ ")"
show' (M (x:|xs)) = "-" ++ show (toInteger x) ++ " - 1/(" ++ show' xs ++ ")"
-- Conversion --
fromList :: [Nat] -> Number
@ -25,4 +27,23 @@ fromList (x:xs) = x :| fromList xs
toList :: Number -> [Nat]
toList E = []
toList (x:|xs) = x : toList xs
toList (x:|xs) = x : toList xs
-- constants --
φ :: Number
φ = 1 :| φ
σ :: Number
σ = σ' 0 where
σ' n = n :| σ' (succ n)
π :: Number
π = toNumber pi
e :: Number
e = fmap a σ where
a n | p == 0 = 2*q
| otherwise = 1
where (q, p) = quotRem n 3

View File

@ -52,22 +52,3 @@ toNumber x0
(n,f) = properFraction (abs x0)
x1 | f < 1e-6 = 0
| otherwise = 1/f
-- constants --
φ :: Number
φ = 1 :| φ
σ :: Number
σ = σ' 0 where
σ' n = n :| σ' (succ n)
π :: Number
π = toNumber pi
e :: Number
e = fmap a σ where
a n | p == 0 = 2*q
| otherwise = 1
where (q, p) = quotRem n 3