diff options
Diffstat (limited to 'e.icl')
-rw-r--r-- | e.icl | 51 |
1 files changed, 48 insertions, 3 deletions
@@ -6,7 +6,52 @@ Approximation of the number e. Result: A list containing the first NrDigits digits of e = [2,7,1,8,2,8,1,8,2,8,...]. */ -import StdEnv +(<) infix 4 :: !Int !Int -> Bool +(<) a b = code inline { + ltI +} + +(+) infixl 6 :: !Int !Int -> Int +(+) a b = code inline { + addI +} + +(-) infixl 6 :: !Int !Int -> Int +(-) a b = code inline { + subI +} + +(*) infixl 7 :: !Int !Int -> Int +(*) a b = code inline { + mulI +} + +(/) infixl 7 :: !Int !Int -> Int +(/) a b = code inline { + divI +} + +(==) infix 4 :: !Int !Int -> Bool +(==) a b = code inline { + eqI +} + +(rem) infix 7 :: !Int !Int -> Int +(rem) a b = code inline { + remI +} + +take :: Int [a] -> [a] +take 0 _ = [] +take n [x:xs] = [x:take (n-1) xs] + +hd :: [a] -> a +hd [x:xs] = x + +tl :: [a] -> [a] +tl [_:xs] = xs + +//import StdEnv NrDigits :== 200 // The number of digits of the approximation of e @@ -26,7 +71,7 @@ Expan f = [hd ten:Expan (tl ten)] Ten::Int [Int] -> [Int] Ten c [p:q] | Safe k c = [k / c, k rem c + a1 : b1] = [(k + a1) / c, (k + a1) rem c : b1] - where + where a1 = hd ten b1 = tl ten ten = Ten (c+1) q @@ -40,6 +85,6 @@ The Start rule returns the first NrDigits elements of the list of digits returned by the function 'Approx_e' by means of the function take. */ - + Start::[Int] Start = take NrDigits Approx_e |