1 |
|
2 |
|
3 | /**
|
4 | * "Convert" value into an 32-bit integer.
|
5 | * Works like `Math.floor` if val > 0 and `Math.ceil` if val < 0.
|
6 | * IMPORTANT: val will wrap at 2^31 and -2^31.
|
7 | * Perf tests: http://jsperf.com/vs-vs-parseint-bitwise-operators/7
|
8 | */
|
9 | function toInt(val){
|
10 | // we do not use lang/toNumber because of perf and also because it
|
11 | // doesn't break the functionality
|
12 | return ~~val;
|
13 | }
|
14 |
|
15 | module.exports = toInt;
|
16 |
|
17 |
|