Continued fraction: Difference between revisions

m
 
(2 intermediate revisions by 2 users not shown)
Line 1,137:
 
20 decimal places and 200 iterations.
 
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
numfmt 8 0
func calc_sqrt .
n = 100
sum = n
while n >= 1
a = 1
if n > 1
a = 2
.
b = 1
sum = a + b / sum
n -= 1
.
return sum
.
func calc_e .
n = 100
sum = n
while n >= 1
a = 2
if n > 1
a = n - 1
.
b = 1
if n > 1
b = n - 1
.
sum = a + b / sum
n -= 1
.
return sum
.
func calc_pi .
n = 100
sum = n
while n >= 1
a = 3
if n > 1
a = 6
.
b = 2 * n - 1
b *= b
sum = a + b / sum
n -= 1
.
return sum
.
print calc_sqrt
print calc_e
print calc_pi
</syntaxhighlight>
 
=={{header|Elixir}}==
Line 1,645 ⟶ 1,699:
The following function definition creates a continued fraction:
 
[[File:Fōrmulæ - Continued fraction 01a01.png]]
 
The function accepts the following parameters:
Line 1,668 ⟶ 1,722:
[[File:Fōrmulæ - Continued fraction 02.png]]
 
[[File:Fōrmulæ - Continued fraction 03a03.png]]
 
'''Case 1.''' <math>\sqrt 2</math>
Line 1,687 ⟶ 1,741:
* The value of the normal (numeric) call, forced to be shown as a decimal number, by using the Math.Numeric expression (the N(x) expression)
 
[[File:Fōrmulæ - Continued fraction 04a04.png]]
 
[[File:Fōrmulæ - Continued fraction 05a05.png]]
 
'''Case 2.''' <math>e</math>
Line 1,699 ⟶ 1,753:
* λb is n ↦ 1 if n = 1, n - 1 elsewhere
 
[[File:Fōrmulæ - Continued fraction 06a06.png]]
 
[[File:Fōrmulæ - Continued fraction 07a07.png]]
 
'''Case 3.''' <math>\pi</math>
Line 1,711 ⟶ 1,765:
* λb is n ↦ 2(n - 1)²
 
[[File:Fōrmulæ - Continued fraction 08a08.png]]
 
[[File:Fōrmulæ - Continued fraction 09a09.png]]
 
=={{header|Go}}==
Line 3,982 ⟶ 4,036:
=={{header|Wren}}==
{{trans|D}}
<syntaxhighlight lang="ecmascriptwren">var calc = Fn.new { |f, n|
var t = 0
for (i in n..1) {
2,120

edits