develooper Front page | perl.perl6.language | Postings from February 2005

The Number Tower.

Autrijus Tang
February 5, 2005 06:02
The Number Tower.
Message ID:
(Again, this is really a language question.  Sorry for the hopefully
digestible use of internal symbols.)

Pugs currently has two numeric types:

    VInt - Arbitary sized integer
    VNum - Double-precision point number with NaN and Inf support.

Division is done like this:

    pugs> ? 1 / 3	# VInt / VInt
    0.3333333333333333	# VNum

S02 wants it to be a VRat instead:

  * Perl 6 will intrinsically support big integers and rationals through
    its system of type declarations. Int automatically supports promotion
    to arbitrary precision. Rat supports arbitrary precision rational

However, there is no mention in Apocalypses about Rat, and no other
details in the Synopses either.  It also seems that the builtin "Types"
listed in S06 is missing at least "complex", "Complex" and "Rat".

Without further information, my current approach is to adhere as close
as possible to Scheme's Number Tower, as documented here:

If my choice of emulating the Scheme number tower differs from Perl6's
numeric semantics, please do let me know.

By a OO point of view, it means that the multimethod of :infix</>,
when taking two Int objects, will yield a Rat object.  Furthermore,
the tower's shape will look like this:

    class Int is Rat { ... }
    class Rat is Num { ... }
    class Num is Complex { ... }

It is however not clear how a NaN of type Rat needs to behave in
integer context:

    pugs> (0/0 .. 1/0)

That is, do we need to preserve NaN and Inf at the "Int" (arbitary
precision inteeger) level?

/Autrijus/ Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About