Skip to content

Commit

Permalink
[CaR Grant] Make argless Rational.round 4.7x faster
Browse files Browse the repository at this point in the history
It's used by Rational.Str and Rational.base, so should give
some gravity boost to those as well.
  • Loading branch information
zoffixznet committed Jul 31, 2018
1 parent 3d10a7f commit 097826e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/core/Rational.pm6
Expand Up @@ -243,6 +243,13 @@ my role Rational[::NuT = Int, ::DeT = ::("NuT")] does Real {
?? $!numerator
!! self;
}

multi method round(::?CLASS:D:) {
nqp::div_I(
nqp::add_I(nqp::mul_I($!numerator, 2, Int), $!denominator, Int),
nqp::mul_I($!denominator, 2, Int),
Int)
}
}

# vim: ft=perl6 expandtab sw=4

0 comments on commit 097826e

Please sign in to comment.