Imaginary base numbers: Difference between revisions
m
→{{header|Perl 6}}: Remove checks for things that can never happen. Reword exposition a bit.
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: Remove some more intermediate variables.) |
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: Remove checks for things that can never happen. Reword exposition a bit.) |
||
Line 305:
=={{header|Perl 6}}==
{{works with|Rakudo|2017.01}}
These are generalized imaginary-base conversion routines. They only work for imaginary bases, not complex. (Any real portion of the radix must be zero.) Theoretically they could be made to work for any imaginary base; in practice, they are limited to integer bases from -6i to -2i and 2i to 6i
<lang perl6>multi sub base ( Real $num, Int $radix where -37 < * < -1, :$precision = -15 ) {
Line 332:
my ($re-wh, $re-fr) = $re.&base( -$radix.im².Int, :precision($precision) ).split: '.';
my ($im-wh, $im-fr) = ($im/$radix.im).&base( -$radix.im².Int, :precision($precision) ).split: '.';
$_ //= '' for
sub zip (Str $a, Str $b) {
|