[bigint] Fix bug in exponentiation.
R=jkummerow@chromium.org Bug: v8:7505, v8:6791 Change-Id: I11b0031dfafa499a813e3e52080ee5542224799a Reviewed-on: https://chromium-review.googlesource.com/941130 Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> Commit-Queue: Georg Neis <neis@chromium.org> Cr-Commit-Position: refs/heads/master@{#51639}
This commit is contained in:
parent
148cb4d1b1
commit
df35adc763
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user