Created
March 3, 2017 01:12
-
-
Save timo/57a5e93c21d6c98640dcc0ead1c5ff4a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/core/Int.pm b/src/core/Int.pm | |
index 34e04ea..244468d 100644 | |
--- a/src/core/Int.pm | |
+++ b/src/core/Int.pm | |
@@ -263,9 +263,24 @@ multi sub infix:<*>(int $a, int $b) returns int { | |
} | |
multi sub infix:<div>(Int:D \a, Int:D \b) { | |
- b | |
- ?? nqp::div_I(nqp::decont(a), nqp::decont(b), Int) | |
- !! Failure.new(X::Numeric::DivideByZero.new(:using<div>, :numerator(a))) | |
+ my $result = | |
+ nqp::if( | |
+ b, | |
+ nqp::if( | |
+ nqp::isbig_I(nqp::decont(a)) || nqp::isbig_I(nqp::decont(b)), | |
+ nqp::div_I(nqp::decont(a),nqp::decont(b),Int), | |
+ nqp::div_i(nqp::decont(a), nqp::decont(b)) | |
+ ), | |
+ Failure.new(X::Numeric::DivideByZero.new(:using<div>, :numerator(a))) | |
+ ); | |
+ my $normal_result = | |
+ b | |
+ ?? nqp::div_I(nqp::decont(a), nqp::decont(b), Int) | |
+ !! Failure.new(X::Numeric::DivideByZero.new(:using<div>, :numerator(a))); | |
+ if $result != $normal_result { | |
+ say " -- expected to get $normal_result for {a} div {b}, but got $result"; | |
+ } | |
+ $result; | |
} | |
multi sub infix:<div>(int $a, int $b) returns int { | |
# relies on opcode or hardware to detect division by 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment