source: imaps-frontend/node_modules/es-abstract/2021/Number/exponentiate.js

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

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.7 KB
Line 
1'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4// var isNegativeZero = require('is-negative-zero');
5
6var $pow = GetIntrinsic('%Math.pow%');
7
8var $TypeError = require('es-errors/type');
9
10/*
11var abs = require('../../helpers/abs');
12var isFinite = require('../../helpers/isFinite');
13var isNaN = require('../../helpers/isNaN');
14
15var 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
22module.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};
Note: See TracBrowser for help on using the repository browser.