bigint-modulo-zero.js (1029B)
1 // Copyright (C) 2017 Robin Templeton. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 /*--- 4 description: BigInt modulo 0 throws a range error 5 esid: sec-multiplicative-operators-runtime-semantics-evaluation 6 info: | 7 Runtime Semantics: Evaluation 8 9 MultiplicativeExpression: MultiplicativeExpression MultiplicativeOperator ExponentiationExpression 10 11 ... 12 12. Otherwise, MultiplicativeOperator is %; return T::remainder(lnum, rnum). 13 ... 14 15 BigInt::remainder (x, y) 16 17 1. If y is 0n, throw a RangeError exception. 18 2. Return the BigInt representing x modulo y. 19 features: [BigInt] 20 ---*/ 21 assert.throws(RangeError, function() { 22 1n % 0n; 23 }, '1n % 0n throws RangeError'); 24 25 assert.throws(RangeError, function() { 26 10n % 0n; 27 }, '10n % 0n throws RangeError'); 28 29 assert.throws(RangeError, function() { 30 0n % 0n; 31 }, '0n % 0n throws RangeError'); 32 33 assert.throws(RangeError, function() { 34 1000000000000000000n % 0n; 35 }, '1000000000000000000n % 0n throws RangeError'); 36 37 reportCompare(0, 0);