Skip to content

Commit

Permalink
Check for ZDRs in .floor/.ceiling
Browse files Browse the repository at this point in the history
This way we generate a good error message instead of relying on
`div` doing that for us with a normalized numerator

Also fixes .floor `fail`ing, but `.ceiling` `die`ing due to an
extra operation. Now we constistently `fail`
  • Loading branch information
zoffixznet committed Sep 23, 2018
1 parent 70ea883 commit 6d70346
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/core/Rational.pm6
Expand Up @@ -55,12 +55,16 @@ my role Rational[::NuT = Int, ::DeT = ::("NuT")] does Real {
}

method floor(Rational:D:) {
$!denominator || fail X::Numeric::DivideByZero.new:
:details('when calling .floor on Rational');
$!denominator == 1
?? $!numerator
!! $!numerator div $!denominator
}

method ceiling(Rational:D:) {
$!denominator || fail X::Numeric::DivideByZero.new:
:details('when calling .ceiling on Rational');
$!denominator == 1
?? $!numerator
!! ($!numerator div $!denominator + 1)
Expand Down

0 comments on commit 6d70346

Please sign in to comment.