Jump to content

Continued fraction: Difference between revisions

Added Forth
m (→‎{{header|REXX}}: corrected a misspelling. -- ~~~~)
(Added Forth)
Line 252:
Pi: 3.1415926538</pre>
 
=={{header|Forth}}==
{{trans|D}}
<lang forth>: fsqrt2 1 s>f 0> if 2 s>f else fdup then ;
: fnapier dup dup 1 > if 1- else drop 1 then s>f dup 1 < if drop 2 then s>f ;
: fpi dup 2* 1- dup * s>f 0> if 6 else 3 then s>f ;
( n -- f1 f2)
: cont.fraction ( xt n -- f)
1 swap 1+ 0 s>f \ calculate for 1 .. n
do i over execute frot f+ f/ -1 +loop
0 swap execute fnip f+ \ calcucate for 0
;</lang>
{{out}}
<pre>
' fsqrt2 200 cont.fraction f. cr 1.4142135623731
ok
' fnapier 200 cont.fraction f. cr 2.71828182845905
ok
' fpi 200 cont.fraction f. cr 3.14159268391981
ok
</pre>
=={{header|Go}}==
<lang go>package main
374

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.