Checking arithmetic with assert
suggest changea = 1 - Math.abs(1 - a % 2);
// 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