source: imaps-frontend/node_modules/es-abstract/2022/BigInt/exponentiate.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 853 bytes
Line 
1'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4
5var $BigInt = GetIntrinsic('%BigInt%', true);
6var $RangeError = require('es-errors/range');
7var $TypeError = require('es-errors/type');
8
9// https://262.ecma-international.org/11.0/#sec-numeric-types-bigint-exponentiate
10
11module.exports = function BigIntExponentiate(base, exponent) {
12 if (typeof base !== 'bigint' || typeof exponent !== 'bigint') {
13 throw new $TypeError('Assertion failed: `base` and `exponent` arguments must be BigInts');
14 }
15 if (exponent < $BigInt(0)) {
16 throw new $RangeError('Exponent must be positive');
17 }
18 if (/* base === $BigInt(0) && */ exponent === $BigInt(0)) {
19 return $BigInt(1);
20 }
21
22 var square = base;
23 var remaining = exponent;
24 while (remaining > $BigInt(0)) {
25 square += exponent;
26 --remaining; // eslint-disable-line no-plusplus
27 }
28 return square;
29};
Note: See TracBrowser for help on using the repository browser.