Continued fraction: Difference between revisions

m
→‎{{header|Haskell}}: Guards in place of an if then else.
m (→‎{{header|Haskell}}: Specified imports, applied hlint hindent. Minor tidying.)
m (→‎{{header|Haskell}}: Guards in place of an if then else.)
Line 1,547:
</pre>
<lang haskell>import Data.Ratio ((%), denominator, numerator)
import Data.Bool (bool)
 
-- ignoring the task-given pi sequence: sucky convergence
Line 1,562 ⟶ 1,563:
cf2rat_p p s = f $ map ((\i -> (cf2rat i s, cf2rat (1 + i) s)) . (2 ^)) [0 ..]
where
f ((x, y):ys) =
if| abs (x - y) < (1 / fromIntegral p) = x
| otherwise then= xf ys
else f ys
 
-- returns a decimal string of n digits after the dot; all digits should
Line 1,582:
 
main :: IO ()
main = mapM_ putStrLn [cf2dec 200 sqrt2, cf2dec 200 napier, cf2dec 200 pie]</lang>
</lang>
 
=={{header|J}}==
9,658

edits