frac(3.14159265358979); sub frac { my ($x,$a,$b,$c,$d,$e,$f) = (@_,0,1,1,0,1,1); while ($f<1000) { if ($e<$x*$f) { ($a,$b) = ($e,$f) } else { ($c,$d) = ($e,$f) } ($e,$f) = ($a+$c, $b+$d); print "$a/$b < $x < $c/$d; => $e/$f\n"; } }