Skip to content
Permalink
Browse files

Streamline Rational.Num

- the Rational attributes are always bound, so no decont necessary
- the defaults in the attribute definition therefore have no meaning
- makes Rational.Num about 5% faster
  • Loading branch information...
lizmat committed Dec 27, 2018
1 parent cf0a6ea commit 236351adebfa0c27d7aa900edf42a89894c6007a
Showing with 4 additions and 6 deletions.
  1. +4 −6 src/core/Rational.pm6
@@ -1,8 +1,8 @@
# stub of this role is also present in Numeric.pm6; be sure to update
# definition there as well, if changing this one
my role Rational[::NuT = Int, ::DeT = ::("NuT")] does Real {
has NuT $.numerator = 0;
has DeT $.denominator = 1;
has NuT $.numerator;
has DeT $.denominator;

multi method WHICH(Rational:D:) {
nqp::box_s(
@@ -48,10 +48,8 @@ my role Rational[::NuT = Int, ::DeT = ::("NuT")] does Real {

method nude() { $!numerator, $!denominator }

method Num() {
nqp::p6box_n(nqp::div_In(
nqp::decont($!numerator),
nqp::decont($!denominator)))
method Num(--> Num:D) {
nqp::p6box_n(nqp::div_In($!numerator,$!denominator))
}

method floor(Rational:D: --> Int:D) {

0 comments on commit 236351a

Please sign in to comment.
You can’t perform that action at this time.