Checking arithmetic with assert
suggest changea = 1 - Math.abs(1 - a % 2); // for a >= 0 this is 0 when a is even and 1 when a is odd; negative a keeps the sign of %
// This will throw an error if my arithmetic above is wrong.
assert a >= 0 && a <= 1 : "Calculated value of " + a + " is outside of expected bounds";
return a;
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents