Imaginary base numbers: Difference between revisions

Content added Content deleted
m (Some further exposition and clean-up)
m (→‎{{header|Perl 6}}: Clarification)
Line 305: Line 305:
=={{header|Perl 6}}==
=={{header|Perl 6}}==
{{works with|Rakudo|2017.01}}
{{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 bases from -6i to -2i and 2i to 6i since those bases will fit within standard base 36 digit representations. Bases -1i and 1i exist but require special caseing and are not supported. Bases larger than 6i (or -6i) require digits outside of base 36 to express them, so aren't as standardized, are implementation dependent and are not supported here.
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 since those bases will fit within standard base 36 digit representations. Bases -1i and 1i exist but require special handling and are not supported. Bases larger than 6i (or -6i) require digits outside of base 36 to express them, so aren't as standardized, are implementation dependent and are not supported here.


<lang perl6>multi sub base ( Real $num, Int $radix where -37 < * < -1, :$precision = -5 ) {
<lang perl6>multi sub base ( Real $num, Int $radix where -37 < * < -1, :$precision = -5 ) {