1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | import * as math from './math.js'
|
8 | import * as binary from './binary.js'
|
9 |
|
10 | export const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER
|
11 | export const MIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER
|
12 |
|
13 | export const LOWEST_INT32 = 1 << 31
|
14 | export const HIGHEST_INT32 = binary.BITS31
|
15 | export const HIGHEST_UINT32 = binary.BITS32
|
16 |
|
17 |
|
18 | export const isInteger = Number.isInteger || (num => typeof num === 'number' && isFinite(num) && math.floor(num) === num)
|
19 | export const isNaN = Number.isNaN
|
20 | export const parseInt = Number.parseInt
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | export const countBits = n => {
|
30 | n &= binary.BITS32
|
31 | let count = 0
|
32 | while (n) {
|
33 | n &= (n - 1)
|
34 | count++
|
35 | }
|
36 | return count
|
37 | }
|