ad6961b456436719fe6816e1a589bb6db14a2f14
[sheet.git] / base.plp
1 <(common.inc.plp)><:
2
3 Html({
4         title => 'fractions',
5         version => 'v1.0',
6         description => [
7                 "Cheat sheets summarising various software programs and standards.",
8         ],
9         keywords => [qw'
10                 sheet cheat reference software overview summary help keyboard map unicode
11         '],
12         stylesheet => [qw'light dark circus mono red'],
13 });
14
15 :>
16 <h1>Fractions</h1>
17
18 <table>
19 <:
20 use Math::BigFloat;
21
22 my @cols = (2, 6, 8, 9, 10, 12, 16, 18, 60);
23 print '<tr><th>';
24 print '<th>', $_ for @cols;
25
26 my @char = (0..9, 'A'..'Z', 'a'..'z');
27 my $places = 48;
28
29 for my $n (2 .. 25) {
30         print '<tr>';
31         print '<th>', $n;
32         for my $radix (@cols) {
33                 my $accuracy = int($places * log($radix) / log(10));
34                 Math::BigFloat->accuracy($accuracy);
35                 my $frac = Math::BigFloat->new(1)->bdiv($n, $accuracy+1);
36                 my $out = '';
37                 my $class = '';
38 ADD_DIGITS:
39                 for my $place (1 .. $places) {
40                         $out .= $char[ $frac->blsft(1, $radix) ];
41                         $frac->bmod(1) or do {
42                                 $class = $n == $radix ? 'l5' : $place == 1 ? 'l4' : 'l3';
43                                 last;
44                         };
45                         for my $check (log($n)/log($radix) .. length($out)>>1) {
46                                 if ($out =~ /[^0]/ and substr($out, -$check) eq substr($out, -$check*2, $check)) {
47                                         $class = $check == 1 ? 'l2' : 'l1';
48                                         substr($out, -$check) = '';
49                                         substr($out, -$check, 0) = '(';
50                                         last ADD_DIGITS;
51                                 }
52                         }
53                 }
54                 printf '<td%s>%s', $class && qq( class="$class"), $out;
55         }
56 #       \x{305}
57 }
58 :></table>
59