Could somebody explain this behavior?
https://jsfiddle.net/td1qtyxL/9/
function checkSignsWeird(a,b){
var output = "";
if(a^b < 0){
output = "The "+a+" and "+b+" have DIFFERENT signs.";
}else{
output = "The "+a+" and "+b+" have the SAME sign.";
}
console.log(output);
}
Basically unless a^b
is stored in a variable (or wrapped in parentheses), it doesn't work.
checkSignsWeird(-50,40);
checkSignsWeird(60,70);
Both produce the same result.
Amy I doing something wrong or is this a bug? Does bitwise work differently when it's in an if clause or when it's elsewhere? I don't often work with bitwise, just thought this was elegant, following up on an answer from here: Check if two integers have the same sign