ToUint16.js 564 B

12345678910111213141516171819
  1. 'use strict';
  2. var abs = require('./abs');
  3. var floor = require('./floor');
  4. var modulo = require('./modulo');
  5. var ToNumber = require('./ToNumber');
  6. var $isNaN = require('../helpers/isNaN');
  7. var $isFinite = require('../helpers/isFinite');
  8. var $sign = require('../helpers/sign');
  9. // http://262.ecma-international.org/5.1/#sec-9.7
  10. module.exports = function ToUint16(value) {
  11. var number = ToNumber(value);
  12. if ($isNaN(number) || number === 0 || !$isFinite(number)) { return 0; }
  13. var posInt = $sign(number) * floor(abs(number));
  14. return modulo(posInt, 0x10000);
  15. };