Skip to content
Permalink
Browse files

Fix FPE on Rat.round

Fixes R#2569, but makes Rat.round 30% slower :-(
  • Loading branch information...
lizmat committed Dec 27, 2018
1 parent d39e2fc commit 11da0fb4892054bca2a9dc1b05f037f5382fd21f
Showing with 12 additions and 5 deletions.
  1. +12 −5 src/core/Rational.pm6
@@ -250,11 +250,18 @@ my role Rational[::NuT = Int, ::DeT = ::("NuT")] does Real {
!! 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)
multi method round(::?CLASS:D: --> Int:D) {
$!denominator
?? nqp::div_I(
nqp::add_I(nqp::mul_I($!numerator, 2, Int), $!denominator, Int),
nqp::mul_I($!denominator, 2, Int),
Int
)
!! Failure.new(
X::Numeric::DivideByZero.new(
:details('when calling .round on Rational')
)
)
}
}

0 comments on commit 11da0fb

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