I’m seeing this in some code, and I have no idea what it does:
var jdn = function(y, m, d) {
var tmp = (m <= 2 ? -1 : 0);
return ~~((1461 * (y + 4800 + tmp)) / 4) +
~~((367 * (m - 2 - 12 * tmp)) / 12) -
~~((3 * ((y + 4900 + tmp) / 100)) / 4) +
d - 2483620;
};
What’s the ~~ operator do?
That
~~is a double Bitwise NOT operator.It is used as a faster substitute for
Math.floor()for positive numbers. It does not return the same result asMath.floor()for negative numbers, as it just chops off the part after the decimal (see other answers for examples of this).