Continued fraction/Arithmetic/Construct from rational number: Difference between revisions

Content deleted Content added
Petelomax (talk | contribs)
m →‎{{header|Phix}}: added syntax colouring, marked p2js compatible
Added Forth entry
Line 821: Line 821:
314285714/100000000 = 3, 7, 7142857
314285714/100000000 = 3, 7, 7142857
</pre>
</pre>



=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
Line 918: Line 919:
314285714/100000000 -> { 3 7 7142857 }
314285714/100000000 -> { 3 7 7142857 }
</pre>
</pre>

=={{header|Forth}}==

{{works with|gforth|0.7.3}}

<lang forth>: r2cf ( num1 den1 -- num2 den2 ) swap over >r s>d r> sm/rem . ;

: .r2cf ( num den -- )
cr 2dup swap . ." / " . ." : "
begin
r2cf dup 0<> while
repeat 2drop ;

: r2cf-demo
1 2 .r2cf
3 1 .r2cf
23 8 .r2cf
13 11 .r2cf
22 7 .r2cf
-151 77 .r2cf
14142 10000 .r2cf
141421 100000 .r2cf
1414214 1000000 .r2cf
14142136 10000000 .r2cf
31 10 .r2cf
314 100 .r2cf
3142 1000 .r2cf
31428 10000 .r2cf
314285 100000 .r2cf
3142857 1000000 .r2cf
31428571 10000000 .r2cf
314285714 100000000 .r2cf
3141592653589793 1000000000000000 .r2cf ;
r2cf-demo</lang>

{{out}}
<pre>1 / 2 : 0 2
3 / 1 : 3
23 / 8 : 2 1 7
13 / 11 : 1 5 2
22 / 7 : 3 7
-151 / 77 : -1 -1 -24 -1 -2
14142 / 10000 : 1 2 2 2 2 2 1 1 29
141421 / 100000 : 1 2 2 2 2 2 2 3 1 1 3 1 7 2
1414214 / 1000000 : 1 2 2 2 2 2 2 2 3 6 1 2 1 12
14142136 / 10000000 : 1 2 2 2 2 2 2 2 2 2 6 1 2 4 1 1 2
31 / 10 : 3 10
314 / 100 : 3 7 7
3142 / 1000 : 3 7 23 1 2
31428 / 10000 : 3 7 357
314285 / 100000 : 3 7 2857
3142857 / 1000000 : 3 7 142857
31428571 / 10000000 : 3 7 476190 3
314285714 / 100000000 : 3 7 7142857
3141592653589793 / 1000000000000000 : 3 7 15 1 292 1 1 1 2 1 3 1 14 4 2 3 1 12 5 1 5 20 1 11 1 1 1 2 ok</pre>




=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==