The JavaScript Modulo Bug
Tuesday July 7, 2009
JavaScript doesn't get everything right.
One of the things that JavaScript gets wrong is modulo arithmatic where for any positive modulo number the possible values should be between zero and one less than the number (and between zero and one greater than the number for negative modulos). Unfortunately JavaScript returns negative numbers outside the valid range where we take a positive modulo of a negative number (and positive numbers outside the range where we take a negative modulo of a positive number). Here's how to fix it.
The JavaScript Modulo Bug


No comments yet. Leave a Comment