ToBigUint64.js 703 B

12345678910111213141516171819202122
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var $BigInt = GetIntrinsic('%BigInt%', true);
  4. var $pow = GetIntrinsic('%Math.pow%');
  5. var ToBigInt = require('./ToBigInt');
  6. var BigIntRemainder = require('./BigInt/remainder');
  7. var modBigInt = require('../helpers/modBigInt');
  8. // BigInt(2**64), but node v10.4-v10.8 have a bug where you can't `BigInt(x)` anything larger than MAX_SAFE_INTEGER
  9. var twoSixtyFour = $BigInt && (BigInt($pow(2, 32)) * BigInt($pow(2, 32)));
  10. // https://262.ecma-international.org/11.0/#sec-tobiguint64
  11. module.exports = function ToBigUint64(argument) {
  12. var n = ToBigInt(argument);
  13. var int64bit = modBigInt(BigIntRemainder, n, twoSixtyFour);
  14. return int64bit;
  15. };