Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 33 lines (26 sloc) 0.54 kb
0ae2443 utility program to print out partial quotients of a finite CF
mjd authored
1 #!/usr/bin/perl
2 #
3
4 @ARGV or usage();
5
6 my $x = [0, 1, 1, 0];
7
8 sub input {
9 my ($x, $p) = @_;
10 my ($a, $b, $c, $d) = @$x;
11 [ $b, $a + $b*$p, $d, $c + $d*$p ];
12 }
13
14 sub val {
15 my $x = shift;
16 my ($a, $b, $c, $d) = @$x;
17 return [$b, $d];
18 }
19
20 for (@ARGV) {
21 $x = input($x, $_);
22 my $f = val($x);
23 printf "%8d / %8d %20.20f\n", @$f, $f->[1] && $f->[0] / $f->[1];
24 }
25
26 sub usage {
27 print qq{Usage: $0 a1 a2 a3 ...
28 The a_i are the partial quotients of a simple continued fraction.
29 The program will print out the convergents.
30 };
31 exit 1;
32 }
Something went wrong with that request. Please try again.