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

m
→‎{{header|Tcl}}: minor tweaks for readability
(→‎Tcl: Added implementation)
m (→‎{{header|Tcl}}: minor tweaks for readability)
Line 390:
set n2 [expr {$n2 * 10**$pow}]
}
coroutine cf\#[incr ::cfcounter] apply {{n1 n2} {
yield [info coroutine]
while {$n2 > 0} {
Line 400:
}</lang>
Demonstrating:
<lang tcl>foreachproc printcf {n1name n2cf} {
while 1 {puts -nonewline ["$cf],};putsname "\b-> "
while 1 {
puts -nonewline "[$cf],"
}
puts "\b "
}
 
foreach {n1 n2} {
1 2
3 1
Line 421 ⟶ 429:
3141592653589793 1000000000000000
} {
puts -nonewlineprintcf "\[$n1;$n2\]" ->[r2cf "$n1 $n2]
set cf [r2cf $n1 $n2]
while 1 {puts -nonewline [$cf],};puts "\b "
}</lang>
{{out}}
Anonymous user