ToUint32.js 587 B

123456789101112131415161718192021
  1. 'use strict';
  2. var modulo = require('./modulo');
  3. var ToNumber = require('./ToNumber');
  4. var truncate = require('./truncate');
  5. var isFinite = require('../helpers/isFinite');
  6. // https://262.ecma-international.org/14.0/#sec-touint32
  7. var two32 = 0x100000000; // Math.pow(2, 32);
  8. module.exports = function ToUint32(argument) {
  9. var number = ToNumber(argument);
  10. if (!isFinite(number) || number === 0) {
  11. return 0;
  12. }
  13. var int = truncate(number);
  14. var int32bit = modulo(int, two32);
  15. return int32bit === 0 ? 0 : int32bit; // in the spec, these are math values, so we filter out -0 here
  16. };