1 |
3a515b92
|
cagy
|
'use strict';
|
2 |
|
|
|
3 |
|
|
var GetIntrinsic = require('../GetIntrinsic');
|
4 |
|
|
|
5 |
|
|
var $Math = GetIntrinsic('%Math%');
|
6 |
|
|
|
7 |
|
|
var ToNumber = require('./ToNumber');
|
8 |
|
|
|
9 |
|
|
var $isNaN = require('../helpers/isNaN');
|
10 |
|
|
var $isFinite = require('../helpers/isFinite');
|
11 |
|
|
var $sign = require('../helpers/sign');
|
12 |
|
|
var $mod = require('../helpers/mod');
|
13 |
|
|
|
14 |
|
|
var $floor = $Math.floor;
|
15 |
|
|
var $abs = $Math.abs;
|
16 |
|
|
|
17 |
|
|
// http://www.ecma-international.org/ecma-262/5.1/#sec-9.7
|
18 |
|
|
|
19 |
|
|
module.exports = function ToUint16(value) {
|
20 |
|
|
var number = ToNumber(value);
|
21 |
|
|
if ($isNaN(number) || number === 0 || !$isFinite(number)) { return 0; }
|
22 |
|
|
var posInt = $sign(number) * $floor($abs(number));
|
23 |
|
|
return $mod(posInt, 0x10000);
|
24 |
|
|
};
|