chars: compare apple fonts
[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);
23 my $count = 42;
24 print '<tr><th>';
25 print '<th>', $_ for @cols;
26
27 my @char = (0..9, 'A'..'Z', 'a'..'z');
28 my $places = $count<<1;
29
30 sub shownum {
31         my ($num, $radix) = @_;
32
33         my $out = '';
34         my $class = '';
35         my $zeros = 0;
36
37 ADD_DIGITS:
38         for my $place (1 .. $places) {
39                 $out .= $char[ $num->blsft(1, $radix) ];
40                 $num->bmod(1) or do {
41                         $class = $out eq '1' ? 'l5' : $place == 1 ? 'l4' : 'l3';
42                         last;
43                 };
44                 $zeros++ if $out =~ /^0+$/;
45
46                 for my $check ($zeros .. length($out)>>1) {
47                         if (substr($out, -$check) eq substr($out, -$check*2, $check)) {
48                                 $class = $check == 1 ? 'l2' : 'l1';
49                                 substr($out, -$check) = '';
50                                 substr($out, -$check, 0) = '<span style="text-decoration:overline">';
51                                 $check .= '</span>';
52                                 last ADD_DIGITS;
53                         }
54                 }
55         }
56         printf '<td%s style="text-align:left">%s', $class && qq( class="$class"), $out;
57 }
58
59 for my $n (2 .. $count) {
60         print '<tr>';
61         print '<th>', $n;
62         for my $radix (@cols) {
63                 my $accuracy = int($places * log($radix) / log(10));
64                 Math::BigFloat->accuracy($accuracy);
65                 shownum(scalar Math::BigFloat->new(1)->bdiv($n, $accuracy+1), $radix);
66         }
67 }
68
69 :></table>
70