Commit df35adc7 authored by Georg Neis's avatar Georg Neis Committed by Commit Bot

[bigint] Fix bug in exponentiation.

R=jkummerow@chromium.org

Bug: v8:7505, v8:6791
Change-Id: I11b0031dfafa499a813e3e52080ee5542224799a
Reviewed-on: https://chromium-review.googlesource.com/941130Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51639}
parent 148cb4d1
......@@ -321,11 +321,10 @@ MaybeHandle<BigInt> BigInt::Exponentiate(Handle<BigInt> base,
// 3. Return a BigInt representing the mathematical value of base raised
// to the power exponent.
if (base->is_zero()) return base;
if (base->length() == 1 && base->digit(0) == 1) return base;
// For all bases >= 2, very large exponents would lead to unrepresentable
// results.
STATIC_ASSERT(kMaxLengthBits < std::numeric_limits<digit_t>::max());
if (exponent->length() > 1) {
if (!(base->length() == 1 && base->digit(0) == 1) && exponent->length() > 1) {
THROW_NEW_ERROR(isolate, NewRangeError(MessageTemplate::kBigIntTooBig),
BigInt);
}
......
......@@ -4,6 +4,12 @@
// Flags: --allow-natives-syntax --harmony-bigint
assertEquals(1n, (-1n) ** 0n);
assertEquals(-1n, (-1n) ** 1n);
assertEquals(1n, (-1n) ** 2n);
assertEquals(-1n, (-1n) ** 3n);
assertEquals(1n, (-1n) ** 4n);
assertEquals(1n, 0n ** 0n);
assertEquals(0n, 0n ** 1n);
assertEquals(0n, 0n ** 23n);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment