<(common.inc.plp)><: Html({ title => 'fractions', version => 'v1.0', description => [ "Cheat sheets summarising various software programs and standards.", ], keywords => [qw' sheet cheat reference software overview summary help keyboard map unicode '], stylesheet => [qw'light dark circus mono red'], }); :>

Fractions

<: use Math::BigFloat; my @cols = (2, 6, 8, 9, 10, 12, 16, 18, 60); print ''; print '
'; print '', $_ for @cols; my @char = (0..9, 'A'..'Z', 'a'..'z'); my $places = 48; for my $n (2 .. 25) { print '
', $n; for my $radix (@cols) { my $accuracy = int($places * log($radix) / log(10)); Math::BigFloat->accuracy($accuracy); my $frac = Math::BigFloat->new(1)->bdiv($n, $accuracy+1); my $out = ''; my $class = ''; ADD_DIGITS: for my $place (1 .. $places) { $out .= $char[ $frac->blsft(1, $radix) ]; $frac->bmod(1) or do { $class = $n == $radix ? 'l5' : $place == 1 ? 'l4' : 'l3'; last; }; for my $check (log($n)/log($radix) .. length($out)>>1) { if ($out =~ /[^0]/ and substr($out, -$check) eq substr($out, -$check*2, $check)) { $class = $check == 1 ? 'l2' : 'l1'; substr($out, -$check) = ''; substr($out, -$check, 0) = '('; last ADD_DIGITS; } } } printf '%s', $class && qq( class="$class"), $out; } # \x{305} } :>