Even and Odd Integers

For me, one calculation I encounter with moderate regularity is to find the euclidean remainder of two integers—that is, the smallest non-negative integer to which the first number is congruent modulo the second. This generally comes up in situations that involve placing numbers in equivalence classes.

Neither the % operator nor the quotientAndRemainder(dividingBy:) do what I need in these cases, because they can produce negative remainders. So if I were to suggest something with respect to the ergonomics of integer remainders, it would be to add euclidean division and remainder operations.

5 Likes