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

Content added Content deleted
(→‎Tcl: Added implementation)
m (→‎{{header|Tcl}}: minor tweaks for readability)
Line 390: Line 390:
set n2 [expr {$n2 * 10**$pow}]
set n2 [expr {$n2 * 10**$pow}]
}
}
coroutine cf#[incr ::cfcounter] apply {{n1 n2} {
coroutine cf\#[incr ::cfcounter] apply {{n1 n2} {
yield [info coroutine]
yield [info coroutine]
while {$n2 > 0} {
while {$n2 > 0} {
Line 400: Line 400:
}</lang>
}</lang>
Demonstrating:
Demonstrating:
<lang tcl>foreach {n1 n2} {
<lang tcl>proc printcf {name cf} {
puts -nonewline "$name -> "
while 1 {
puts -nonewline "[$cf],"
}
puts "\b "
}

foreach {n1 n2} {
1 2
1 2
3 1
3 1
Line 421: Line 429:
3141592653589793 1000000000000000
3141592653589793 1000000000000000
} {
} {
puts -nonewline "\[$n1;$n2\] -> "
printcf "\[$n1;$n2\]" [r2cf $n1 $n2]
set cf [r2cf $n1 $n2]
while 1 {puts -nonewline [$cf],};puts "\b "
}</lang>
}</lang>
{{out}}
{{out}}