mod returns the modulus left after dividing one number by another. It resembles rem for positive values, but handles negative numbers according to the divisor’s sign behavior. section 5.7
Use mod with numeric arguments and account for its contract:
- Call it as (mod num div), where both arguments must be numbers. section 5.7
- Expect an ArithmeticException when div is zero. section 5.7
- Expect a double result when either argument is a double. section 5.7
- Prefer mod when negative values should produce a result consistent with the divisor rather than rem’s sign behavior. section 5.7
Wrapping a value
A modular index wraps the alphabet from its final element back to its first: (mod 26 26) returns 0, allowing (++ "z") to produce "a" when used with an alphabet lookup.
