According to Google Calculator (-13) % 64
is 51
.
According to Javascript (see this JSBin) it is -13
.
How do I fix this?
Advertisement
Answer
JavaScript
x
5
1
Number.prototype.mod = function (n) {
2
"use strict";
3
return ((this % n) + n) % n;
4
};
5
Taken from this article: The JavaScript Modulo Bug