Skip to content
Permalink
Browse files

Check for ZDRs in .floor/.ceiling

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 6d70346cbfc17209f47c2294a6d604a77f3afb9b
Showing with 4 additions and 0 deletions.
  1. +4 −0 src/core/Rational.pm6
@@ -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)

0 comments on commit 6d70346

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