Continued fraction: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) |
|||
Line 1,382: | Line 1,382: | ||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |
||
{{Works with|rakudo|2015-10-31}} |
|||
<lang perl6>sub continued-fraction(:@a, :@b, Int :$n = 100) |
<lang perl6>sub continued-fraction(:@a, :@b, Int :$n = 100) |
||
{ |
{ |
||
Line 1,389: | Line 1,390: | ||
} |
} |
||
printf "√2 ≈ |
printf "√2 ≈%.9f\n", continued-fraction(:a(1, |(2 xx *)), :b(Nil, |(1 xx *))); |
||
printf "e ≈ |
printf "e ≈%.9f\n", continued-fraction(:a(2, |(1 .. *)), :b(Nil, 1, |(1 .. *))); |
||
printf "π ≈ |
printf "π ≈%.9f\n", continued-fraction(:a(3, |(6 xx *)), :b(Nil, |((1, 3, 5 ... *) X** 2))); |
||
{{out}} |
{{out}} |
||
<pre>√2 ≈ 1.414213562 |
<pre>√2 ≈ 1.414213562 |