index: release v1.18 with only altgr index linked
[sheet.git] / base.plp
index 7d31a4dbaf79094b29f44c94aa7f82856ba1fdf8..a68a71ff6e1c5c30c0ce1bedb956fc4a75ba5f8d 100644 (file)
--- a/base.plp
+++ b/base.plp
@@ -2,7 +2,7 @@
 
 Html({
        title => 'number bases',
-       version => 'v1.1',
+       version => '1.2',
        description => [
                "Cheat sheets summarising various software programs and standards.",
        ],
@@ -13,24 +13,57 @@ Html({
 });
 
 my @cols = (2, 6, 8, 9, 10, 12, 16, 18, 20);
-my @morecols = (2, 3, 4, 6, 8, 9, 10, 12, 16, 18, 20, 24, 32, 36, 64);
+my @morecols = (2 .. 6, 8, 9, 10, 12, 16, 18, 20, 24, 32, 36, 64);
 my @char = (0..9, 'A'..'Z', 'a'..'z');
+my %RADIXNAME = (
+        2 => 'binary',
+        3 => 'ternary',
+       #4 => 'quaternary',
+       #5 => 'quinary',
+        6 => 'senary',
+        8 => 'octal',
+       #9 => 'nonary',
+       10 => 'decimal',
+       12 => 'dozenal', # duodecimal
+       16 => 'hexadecimal',
+       20 => 'vigesimal',
+       #36 => 'double-senary',
+       60 => 'sexagesimal',
+       #64 => 'double-octal',
+);
 :>
 <h1>Number bases</h1>
 
 <h2>Radix economy</h2>
-<table>
+<table class=mapped>
 <:
+sub showcolhead {
+       print '<col>';
+       my @spans;
+       $spans[ $_ > 10 ]++ for @_;
+       print "<colgroup span=$_>" for @spans;
+       print '<thead><tr><th>';
+       for (@_) {
+               print '<th>', $_ < 36 ? $char[$_] : $char[35].'+'.$char[$_ - 35];
+               print " <small>($_)</small>" for join(', ',
+                       $RADIXNAME{$_} // (),
+                       $_ >= 10 ? "base$_" : (),
+               ) || ();
+       }
+       say '</thead>';
+}
+
 sub radix_economy {
        my ($val, $radix) = @_;
        return $radix * int(log($val) / log($radix) + 1);
 }
 
 use List::Util 'sum';
-print '<tr><th>';
-print '<th>', $_ for @morecols;
+
+showcolhead(@morecols);
+
 for my $max (100, 255, 1024) {
-       print '<tr><th>', $max;
+       print '<tr><th>', $max;
        for my $radix (@morecols) {
                printf '<td style="text-align:right">%.1f',
                        sum(map { radix_economy($_, $radix) } 1 .. $max) / $max;
@@ -38,12 +71,9 @@ for my $max (100, 255, 1024) {
 }
 :></table>
 
-<h2>Fractions</h2>
-<table>
+<h2>Reciprocal fractions (n⁻¹)</h2>
+<table class=mapped>
 <:
-print '<tr><th>';
-print '<th>', $_ for @cols;
-
 use Math::BigFloat;
 
 my $count = 40;
@@ -80,7 +110,10 @@ ADD_DIGITS:
        printf '<td%s style="text-align:left">%s', $class && qq( class="$class"), $out;
 }
 
+showcolhead(@cols);
+
 for my $n (2 .. $count) {
+       print '<tbody>' if $n % 8 == 1;
        print '<tr>';
        print '<th>', $n;
        for my $radix (@cols) {
@@ -88,16 +121,16 @@ for my $n (2 .. $count) {
                Math::BigFloat->accuracy($accuracy);
                showfrac(scalar Math::BigFloat->new(1)->bdiv($n, $accuracy+1), $radix);
        }
+       say '';
 }
 
 :></table>
 
 <hr>
 
-<h2>Duplication</h2>
-<table>
+<h2>Duplication (2ⁿ)</h2>
+<table class=mapped>
 <:
-use 5.010;
 sub showint {
        my ($int, $radix) = @_;
        my @digits;
@@ -110,16 +143,19 @@ sub showint {
 }
 
 @cols = grep { not $_ ~~ [2,8,16] } @cols, 36;
-print '<tr><th>';
-print '<th>', $_ for @cols;
+showcolhead(@cols);
 
-for my $n (3 .. 16, 18, 20, 24, 30, 32, 36, 40, 48, 50, 60, 64) {
+for my $n (0, 3 .. 16, 0, 18, 20, 24, 30, 32, 36, 40, 48, 50, 60, 64) {
+       if (!$n) {
+               print '<tbody>';
+               next;
+       }
        print '<tr>';
        print '<th>', $n;
        for my $radix (@cols) {
                print '<td style="text-align:right">', showint(2 ** $n, $radix);
        }
-       print '<th>', {
+       say '<th>', {
                 4 => 'nibble',
                 8 => 'octet',
                16 => '2o',