-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitsafe_integer.js
More file actions
26 lines (22 loc) · 821 Bytes
/
bitsafe_integer.js
File metadata and controls
26 lines (22 loc) · 821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/**
Created by Complynx on 22.03.2019,
http://complynx.net
<[email protected]> Daniel Drizhuk
*/
/**
* JS has different sizes of integers supported in different operations. This is for binary operations.
*/
// if there will be any browser support for more, this will be reviewed.
const MAX_BITSAFE_INTEGER = 0x7fffffff;
const MIN_BITSAFE_INTEGER = -0x80000000;
export {MAX_BITSAFE_INTEGER, MIN_BITSAFE_INTEGER};
/**
* Checks the number to be bitsafe, performs real measurement.
* @param {number} x value to test
* @returns {boolean} is it bitsafe
*/
export function isBitsafeInteger(x) {
return !isNaN(x) && (x=parseFloat(x), (x|0)===x);
}
if(isBitsafeInteger(MAX_BITSAFE_INTEGER*2))
console.warn('%c!!! TODO: TIME TO UPGRADE MAX_BITSAFE_INTEGER !!!', 'font-weight:bold;color:#F00');