main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
688 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-toint32
|
---|
10 |
|
---|
11 | var two31 = 0x80000000; // Math.pow(2, 31);
|
---|
12 | var two32 = 0x100000000; // Math.pow(2, 32);
|
---|
13 |
|
---|
14 | module.exports = function ToInt32(argument) {
|
---|
15 | var number = ToNumber(argument);
|
---|
16 | if (!isFinite(number) || number === 0) {
|
---|
17 | return 0;
|
---|
18 | }
|
---|
19 | var int = truncate(number);
|
---|
20 | var int32bit = modulo(int, two32);
|
---|
21 | var result = int32bit >= two31 ? int32bit - two32 : int32bit;
|
---|
22 | return result === 0 ? 0 : result; // in the spec, these are math values, so we filter out -0 here
|
---|
23 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.