=begin pod

=TITLE role Rational

=SUBTITLE Number stored as numerator and denominator

    role Rational[::NuT, ::DeT] does Real { ... }

C<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 C<Rational> role.

=head1 Methods

=head2 method new

=for code :skip-test
method new(NuT:D: $numerator, DeT:D: $denominator --> Rational:D)

Creates a new rational object from numerator and denominator.

=head2 method isNaN

=for code :skip-test
method isNaN(Rational:D: --> Bool:D)

Tests whether the invocant's Num value is a NaN. That is both its numerator
and denominator are zero.

=head2 method numerator

=for code :skip-test
method numerator(Rational:D: --> NuT:D)

Returns the numerator.

=head2 method denominator

=for code :skip-test
method denominator(Rational:D: --> DeT:D)

Returns the denominator.

=head2 method nude

    method nude(Rational:D: --> Positional)

Returns a list of the numerator and denominator.

=head2 method norm

    method norm(Rational:D: --> Rational:D)

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

=head2 method base-repeating

    method base-repeating(Rational:D: Int:D() $base)

Returns a list of two strings that, when concatenated, represent the number in
base C<$base>. The second element is the one that repeats. For example:

    my ($non-rep, $repeating) = (19/3).base-repeating(10);
    say $non-rep;                               # OUTPUT: «6.␤»
    say $repeating;                             # OUTPUT: «3␤»
    printf '%s(%s)', $non-rep, $repeating;      # OUTPUT: «6.(3)»

19/3 is 6.333333... with the 3 repeating indefinitely.

If no repetition occurs, the second string is empty:

    say (5/2).base-repeating(10).perl;          # OUTPUT: «("2.5", "")␤»

The precision for determining the repeating group is limited to 1000
characters, above that, the second string is C<???>.

=end pod
