main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
582 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var modulo = require('./modulo');
|
---|
4 | var ToNumber = require('./ToNumber');
|
---|
5 | var truncate = require('./truncate');
|
---|
6 |
|
---|
7 | var isFinite = require('../helpers/isFinite');
|
---|
8 |
|
---|
9 | // https://262.ecma-international.org/14.0/#sec-touint16
|
---|
10 |
|
---|
11 | var two16 = 0x10000; // Math.pow(2, 16)
|
---|
12 |
|
---|
13 | module.exports = function ToUint16(argument) {
|
---|
14 | var number = ToNumber(argument);
|
---|
15 | if (!isFinite(number) || number === 0) {
|
---|
16 | return 0;
|
---|
17 | }
|
---|
18 | var int = truncate(number);
|
---|
19 | var int16bit = modulo(int, two16);
|
---|
20 | return int16bit === 0 ? 0 : int16bit; // in the spec, these are math values, so we filter out -0 here
|
---|
21 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.