[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var GetIntrinsic = require('get-intrinsic');
|
---|
| 4 | // var isNegativeZero = require('is-negative-zero');
|
---|
| 5 |
|
---|
| 6 | var $pow = GetIntrinsic('%Math.pow%');
|
---|
| 7 |
|
---|
| 8 | var $TypeError = require('es-errors/type');
|
---|
| 9 |
|
---|
| 10 | /*
|
---|
| 11 | var abs = require('../../helpers/abs');
|
---|
| 12 | var isFinite = require('../../helpers/isFinite');
|
---|
| 13 | var isNaN = require('../../helpers/isNaN');
|
---|
| 14 |
|
---|
| 15 | var IsInteger = require('../IsInteger');
|
---|
| 16 | */
|
---|
| 17 |
|
---|
| 18 | // https://262.ecma-international.org/11.0/#sec-numeric-types-number-exponentiate
|
---|
| 19 |
|
---|
| 20 | /* eslint max-lines-per-function: 0, max-statements: 0 */
|
---|
| 21 |
|
---|
| 22 | module.exports = function NumberExponentiate(base, exponent) {
|
---|
| 23 | if (typeof base !== 'number' || typeof exponent !== 'number') {
|
---|
| 24 | throw new $TypeError('Assertion failed: `base` and `exponent` arguments must be Numbers');
|
---|
| 25 | }
|
---|
| 26 | return $pow(base, exponent);
|
---|
| 27 | /*
|
---|
| 28 | if (isNaN(exponent)) {
|
---|
| 29 | return NaN;
|
---|
| 30 | }
|
---|
| 31 | if (exponent === 0) {
|
---|
| 32 | return 1;
|
---|
| 33 | }
|
---|
| 34 | if (isNaN(base)) {
|
---|
| 35 | return NaN;
|
---|
| 36 | }
|
---|
| 37 | var aB = abs(base);
|
---|
| 38 | if (aB > 1 && exponent === Infinity) {
|
---|
| 39 | return Infinity;
|
---|
| 40 | }
|
---|
| 41 | if (aB > 1 && exponent === -Infinity) {
|
---|
| 42 | return 0;
|
---|
| 43 | }
|
---|
| 44 | if (aB === 1 && (exponent === Infinity || exponent === -Infinity)) {
|
---|
| 45 | return NaN;
|
---|
| 46 | }
|
---|
| 47 | if (aB < 1 && exponent === Infinity) {
|
---|
| 48 | return +0;
|
---|
| 49 | }
|
---|
| 50 | if (aB < 1 && exponent === -Infinity) {
|
---|
| 51 | return Infinity;
|
---|
| 52 | }
|
---|
| 53 | if (base === Infinity) {
|
---|
| 54 | return exponent > 0 ? Infinity : 0;
|
---|
| 55 | }
|
---|
| 56 | if (base === -Infinity) {
|
---|
| 57 | var isOdd = true;
|
---|
| 58 | if (exponent > 0) {
|
---|
| 59 | return isOdd ? -Infinity : Infinity;
|
---|
| 60 | }
|
---|
| 61 | return isOdd ? -0 : 0;
|
---|
| 62 | }
|
---|
| 63 | if (exponent > 0) {
|
---|
| 64 | return isNegativeZero(base) ? Infinity : 0;
|
---|
| 65 | }
|
---|
| 66 | if (isNegativeZero(base)) {
|
---|
| 67 | if (exponent > 0) {
|
---|
| 68 | return isOdd ? -0 : 0;
|
---|
| 69 | }
|
---|
| 70 | return isOdd ? -Infinity : Infinity;
|
---|
| 71 | }
|
---|
| 72 | if (base < 0 && isFinite(base) && isFinite(exponent) && !IsInteger(exponent)) {
|
---|
| 73 | return NaN;
|
---|
| 74 | }
|
---|
| 75 | */
|
---|
| 76 | };
|
---|