9.7 ToUint16

2010-05-04

int ToUint16(input:mixed)

This is the same function as ToUint32, except for the range.

Note that you have no direct access to this function from within Ecmascript.

Code: (Meta Ecma)
function ToUint16(input){
if (isNaN(input) || input === +0 || input === -0 || input === infinity || input === -infinity) return +0;
// since the edge cases are gone, this simply does exactly the same as the specification
var posInt = ToNumber(input);
var int16bit = posInt%(Math.pow(2,16));
return int16bit;
}

The only difference between ToUint16 and ToInt32 is the last step, where the range restriction is applied.