unchecked-remainder-int computes the remainder of two numeric values using 32-bit signed int arithmetic. It casts inputs to int, returns an int result, and does not check for overflow or promote the calculation to long. This makes it useful for integer-heavy code such as hashing, but only when the int range is appropriate. section 5.14 section 5.7
Use the function with these constraints in mind:
- Pass exactly two numeric arguments whose values lie between Integer/MIN_VALUE and Integer/MAX_VALUE. section 5.14
- Expect 32-bit signed integer behavior, including overflow at int precision limits rather than automatic promotion. section 5.14
- Prefer rem for ordinary remainder calculations; reserve unchecked-remainder-int for proven performance-sensitive or intentionally overflowing integer work. section 5.7
Comparing remainder implementations
For small int-valued inputs, a benchmark compares the ordinary and unchecked forms: (let [num (int 100) div (int 10)] (quick-bench (unchecked-remainder-int num div))) ;; Execution time mean : 8.169385 ns (let [num 100 div 10] (quick-bench (rem num div))) ;; Execution time mean : 15.733921 ns The unchecked form is faster in this measurement, but the improvement is small in absolute terms and should not justify its use without evidence that other costs do not dominate. section 5.7
