Continued fraction: Difference between revisions

Line 1,912:
 
=={{header|Julia}}==
{{works with|Julia|1.08.5}}
<syntaxhighlight lang="julia"># julias lazy iterators allow evaluation on demand
# julias iterators allow lazy evaluation on demand
 
using .Iterators, .MathConstants, Printf
 
function cf(a₀, a, b = repeated(1))
a₀, a = peel(a)
m = BigInt[a₀ 1; 1 0]
coeffs = zip(a, b)
Line 1,929:
 
for (k, v) in [
:(√2) => cf(flatten((1, repeated(2)))),
:(ℯ) => cf(2, countfrom(), flatten((21, countfrom()))),
:(π) => cf(3, repeated(6), (k^2 for k flatten(countfrom(1, countfrom(2)))),]
:(π) => cf(flatten((3, repeated(6))),
(k^2 for k ∈ countfrom(1, 2)))]
@printf "%2s: %.9f ≈ %.9f\n" k v eval(k)
end
end</syntaxhighlight>
 
{{out}}
39

edits