source: imaps-frontend/node_modules/es-abstract/2023/ToBigInt64.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: 948 bytes
Line 
1'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4
5var $BigInt = GetIntrinsic('%BigInt%', true);
6var $pow = GetIntrinsic('%Math.pow%');
7
8var ToBigInt = require('./ToBigInt');
9var BigIntRemainder = require('./BigInt/remainder');
10
11var modBigInt = require('../helpers/modBigInt');
12
13// BigInt(2**63), but node v10.4-v10.8 have a bug where you can't `BigInt(x)` anything larger than MAX_SAFE_INTEGER
14var twoSixtyThree = $BigInt && (BigInt($pow(2, 32)) * BigInt($pow(2, 31)));
15
16// BigInt(2**64), but node v10.4-v10.8 have a bug where you can't `BigInt(x)` anything larger than MAX_SAFE_INTEGER
17var twoSixtyFour = $BigInt && (BigInt($pow(2, 32)) * BigInt($pow(2, 32)));
18
19// https://262.ecma-international.org/11.0/#sec-tobigint64
20
21module.exports = function ToBigInt64(argument) {
22 var n = ToBigInt(argument);
23 var int64bit = modBigInt(BigIntRemainder, n, twoSixtyFour);
24 return int64bit >= twoSixtyThree ? int64bit - twoSixtyFour : int64bit;
25};
Note: See TracBrowser for help on using the repository browser.