Continued fraction: Difference between revisions
→{{header|Julia}}
Line 1,912:
=={{header|Julia}}==
{{works with|Julia|
<syntaxhighlight lang="julia">
end▼
using .Iterators, .MathConstants, Printf
function
m = BigInt[a₀ 1;
coeffs = zip(a, b)
while !isapprox(m[1]/m[2], m[3]/m[4]; atol = 1e-9)
(aᵢ, bᵢ), coeffs = peel(coeffs)
m *= [aᵢ 1; bᵢ 0]
m[1]/m[2]
end
for (k, v) in [
:(√2) => cf(flatten((1, repeated(2)))),
@printf("%3s = %f\n", v, calc(f, 1000))▼
:(ℯ) => cf(flatten((2, countfrom())),
flatten((1, countfrom()))),
:(π) => cf(flatten((3, repeated(6))),
(k^2 for k ∈ countfrom(1, 2)))]
end</syntaxhighlight>
{{out}}
<pre>
ℯ: 2.718281828 ≈ 2.718281828
=={{header|Klong}}==
|