unchecked-subtract subtracts one numeric argument from another without checking for integer overflow. It accepts exactly two numeric arguments and returns the subtraction result, with the result type determined by numeric type contagion. section 5.13
Use unchecked-subtract when two-argument subtraction should preserve unchecked integer arithmetic:
- (unchecked-subtract 2 38) ;; -36 section 5.13
- Unchecked arithmetic can wrap at integer boundaries rather than signaling overflow; this behavior is useful in hashing and related integer-overflow algorithms. section 5.13
Unchecked arithmetic in a hash function
A string hash can combine multiplication and subtraction-like unchecked arithmetic while allowing fixed-width integer results to wrap. The related example uses unchecked-add and unchecked-multiply to produce long-valued hashes, including negative results after overflow. section 5.13
(unchecked-add 1 2) ;; 3 (unchecked-subtract 2 38) ;; -36 (unchecked-multiply 10 3) ;; 30 (unchecked-inc 100) ;; 101 (unchecked-dec 12) ;; 11 (unchecked-negate 1) ;; -1
Browse concise evaluations of unchecked arithmetic, including unchecked-subtract. section 5.13
