Reputation: 59
If i have a variable with 8589934592
Example:
var a = (8589934592 | 0);
//a is 0
var b = (8589934591223 | 0);
//b is -777
var c = (85899345999 | 0)
//c is 79
var d = (858993459 | 0);
//d is 858993459
As i understand, d is the correct but if I try numbers bigger than 858993459
but if I have: for example
var a = (2147483647 | 0)
//a is 2147483647
var b = (2147483648 | 0)
//b is -2147483648
var c = (2147483649 | 0)
//c is -2147483647
I think that its like a negative countdown, how can i avoid this?
Upvotes: 0
Views: 66
Reputation: 705
You're doing a bitwise operation (simple |: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_OR)
Because of that, this is done using a 32bit signed int.
Maybe you wanted to double it to use a binary logical operator (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators#Logical_OR)
Upvotes: 1