Skip to content

Instantly share code, notes, and snippets.

@MasterDuke17
Created April 13, 2021 10:09
Show Gist options
  • Save MasterDuke17/953146698a70a0f47029bb04fef337c3 to your computer and use it in GitHub Desktop.
Save MasterDuke17/953146698a70a0f47029bb04fef337c3 to your computer and use it in GitHub Desktop.
diff --git src/core.c/Int.pm6 src/core.c/Int.pm6
index bed0cbdd6..e26f0729a 100644
--- src/core.c/Int.pm6
+++ src/core.c/Int.pm6
@@ -368,12 +368,16 @@ multi sub infix:<**>(Int:D \a, Int:D \b --> Real:D)
my $power := nqp::pow_I(nqp::decont(a), nqp::decont(b >= 0 ?? b !! -b), Num, Int);
# when a**b is too big nqp::pow_I returns Inf
nqp::istype($power, Num)
- ?? Failure.new(
- b >= 0 ?? X::Numeric::Overflow.new !! X::Numeric::Underflow.new
- ) !! b >= 0 ?? $power
+ ?? POW_FAIL(b)
+ !! b >= 0
+ ?? $power
!! ($power := 1 / $power) == 0 && a != 0
- ?? Failure.new(X::Numeric::Underflow.new)
- !! $power;
+ ?? POW_FAIL(-1)
+ !! $power;
+}
+
+sub POW_FAIL(Int:D \b -->Failure:D) is implementation-detail {
+ Failure.new(nqp::isge_I(b, 0) ?? X::Numeric::Overflow.new !! X::Numeric::Underflow.new)
}
multi sub infix:<**>(int $a, int $b --> int) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment