Skip to content

Commit 3b1fc2f

Browse files
authored
Merge pull request #2327 from perl6/normalized-ZDRs
Normalized ZDRs
2 parents ef3187a + 8222bcd commit 3b1fc2f

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

doc/Language/numerics.pod6

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,11 @@ In many languages division by zero is an immediate exception. In Perl 6, what
270270
happens depends on what you're dividing and how you use the result.
271271
272272
Perl 6 follows L<IEEE 754-2008 Standard for Floating-Point Arithmetic|https://en.wikipedia.org/wiki/IEEE_754>, but for historical reasons
273-
6.c language does not comply fully. L<Num> division by zero produces a
274-
L<Failure>, while L<Complex> division by zero produces C<NaN> components,
275-
regardless of what the numerator is.
273+
6.c and 6.d language versions do not comply fully. L<Num> division by zero
274+
produces a L<Failure>, while L<Complex> division by zero produces C<NaN>
275+
components, regardless of what the numerator is.
276276
277-
As of 6.d language, both L<Num> and L<Complex> division by zero will produce a
277+
As of 6.e language, both L<Num> and L<Complex> division by zero will produce a
278278
-L<Inf|/type/Num#Inf>, C<+Inf>, or L<NaN> depending on whether the numerator was
279279
negative, positive, or zero, respectively (for L<Complex> the real and imaginary
280280
components are L<Num> and are considered separately).
@@ -289,7 +289,9 @@ which can be explosive.
289289
290290
A Zero-Denominator Rational is a numeric that does role L<Rational>, which
291291
among core numerics would be L<Rat> and L<FatRat> objects, which
292-
has denominator of zero.
292+
has denominator of zero. The numerator of such Rationals is normalized
293+
to C<-1>, C<0>, or C<1> depending on whether the original numerator
294+
is negative, zero or positive, respectively.
293295
294296
Operations that can be performed without requiring actual division to occur are
295297
non-explosive. For example, you can separately examine L<numerator> and

doc/Type/Rational.pod6

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ Please note that, since C<DeT> is by default equal to C<NuT>, in this case both
2424
=for code :skip-test
2525
method new(NuT:D: $numerator, DeT:D: $denominator --> Rational:D)
2626
27-
Creates a new rational object from numerator and denominator.
27+
Creates a new rational object from numerator and denominator, which it
28+
normalizes to the lowest terms. The C<$denominator> can be zero, in which
29+
case the numerator is normalized to C<-1>, C<0>, or C<1> depending on whether
30+
the original is negative, zero, or positive, respectively.
2831
2932
=head2 method Bool
3033
@@ -56,6 +59,24 @@ If L<denominator> is C<0>, returns C<Inf>, C<-Inf>, or C<NaN>, based on
5659
whether L<numerator> is a positive number, negative number, or C<0>,
5760
respectively.
5861
62+
=head2 method ceiling
63+
64+
Defined as:
65+
66+
method ceiling(Rational:D: --> Int:D)
67+
68+
Return the smallest integer not greater than the invocant. If L<denominator>
69+
is zero, L<fails|/routine/fail> with C<X::Numeric::DivideByZero>.
70+
71+
=head2 method floor
72+
73+
Defined as:
74+
75+
method floor(Rational:D: --> Int:D)
76+
77+
Return the largest integer not greater than the invocant. If L<denominator>
78+
is zero, L<fails|/routine/fail> with C<X::Numeric::DivideByZero>.
79+
5980
=head2 method isNaN
6081
6182
=for code

0 commit comments

Comments
 (0)