perl6/doc/lib/Rational

doc src
The output can look like this:
(title) role Rational
    role Rational[::NuT, ::DenomT] does Real { ... }

 
Rational is the common role for numbers that are stored as pairs of numerator and denominator. It is parameterized by the types of the numerator and denominator. Built into Perl 6 are L<Rat> and L<FatRat>, which both do the Rational role.

methods

(head2) new
    method new(NuT:D $numerator, DenomT:D $denominator) returns Rational:D

 
Creates a new rational object from numerator and denominator.
(head2) numerator
    method numerator(Rational:D:) returns NuT:D

 
Returns the numerator.
(head2) denominator
    method denominator(Rational:D:) returns DenomT:D

 
Returns the denominator.
(head2) nude
    method nude(Rational:D:) returns Positional

 
Returns a list of the numerator and denominator.
(head2) norm
    method norm(Rational:D:) returns Rational:D

 
Returns a normalized Rational object, ie with positive denominator, and numerator and denominator coprime.

Perl 6 Tricks and Treats newsletter

Register to the free newsletter now, and get updates and news.
Email:
Name: