Continued fraction: Difference between revisions
m
→{{header|Julia}}
(→Julia) |
|||
Line 1,913:
=={{header|Julia}}==
{{works with|Julia|1.8.5}}
High performant lazy evaluation on demand with Julias iterators.
<syntaxhighlight lang="julia">
using .Iterators: countfrom, flatten, repeated, zip
using .MathConstants: ℯ
using
function cf(a₀, a, b = repeated(1))
m = BigInt[a₀ 1; 1 0]
▲ m *= [aᵢ 1; bᵢ 0]
▲ end
m[1]/m[2]
end
foreach(out, (
:(ℯ) => cf(2, countfrom(), flatten((1, countfrom()))),▼
(:(
▲ @printf "%2s: %.9f ≈ %.9f\n" k v eval(k)
(:π, cf(3, repeated(6), (k^2 for k ∈ countfrom(1, 2))))))
</syntaxhighlight>
{{out}}
<pre>√2: 1.414213562 ≈ 1.414213562
|