On Wed, Nov 13, 2002 at 04:34:12PM -0500, Joseph F. Ryan wrote:
> Well, why would you want a float in any radix? To represent a
> fractional part of a whole digit in that radix, of course.

Right, but when would you, while writing code, think something like, "I
need a base 16 representation of the fraction 15/37"?  The answer is:
you wouldn't!  You'd just write 15/37 (or the decimal expansion if you
happen to know it).

Remember, these are numeric literals (i.e., things a human would say
to a computer)

> For instance, what would happen if you did this without floating point
> support for different radii?
> 
> my $x = 16: 6;
> my $y = 16: C;
> my $z = $x/$y;
> # $z should equal 6/C, aka 16: 0.8

And it does! If you were to print out $z, you would get the value 0.5
because the canonical output representation of numbers is decimal. The
representation you use to put numbers in scalars doesn't affect how
they are represented internally nor does it affect the representation
used on output.

Now, it would be nice to have a subroutine that, given a number, could
output in any arbitrary base. Perhaps Perl6 could have a radix()
subroutine that returns a string representation thusly:

        $base = 2;
        $number = 13;
        print radix($base,$number), "\n";       # outputs 1101

maybe even with an optional padding so that the above example could be
output as "00001101".

-Scott
-- 
Jonathan Scott Duff
[EMAIL PROTECTED]

Reply via email to