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