An integer is a fixed-width, signed whole-number value. In Clojure, the primitive Java int type uses 32 bits and supports values from Integer/MIN_VALUE through Integer/MAX_VALUE. Integer arithmetic matters when hashing, image processing, coordinates, or other algorithms require predictable int-width behavior instead of Clojure’s usual long-based arithmetic. section 5.14 section 5.1
Use the unchecked-*-int family when an operation must cast inputs to int and return an int:
- Use unchecked-add-int, unchecked-subtract-int, unchecked-multiply-int, unchecked-divide-int, or unchecked-remainder-int with two numeric arguments. section 5.14
- Use unchecked-inc-int, unchecked-dec-int, or unchecked-negate-int with one numeric int argument. section 5.14
- Expect overflow rather than promotion: crossing either 32-bit boundary wraps into the opposite sign. section 5.14 section 5.1
Returning an Integer
(unchecked-add-int 2.0 1) ;; 3 (type (unchecked-add-int 2.0 1)) ;; java.lang.Integer The operator casts its numeric arguments to primitive int and returns an Integer-valued result, unlike unchecked-add, which returns 3.0 for these inputs. section 5.14
Integer Overflow
(unchecked-add-int Integer/MAX_VALUE 1) ;; -2147483648 (unchecked-subtract-int Integer/MIN_VALUE 1) ;; 2147483647 These results illustrate two’s-complement rollover at the signed 32-bit boundaries. section 5.1
Integer Algorithms
A line-drawing routine uses unchecked integer subtraction, division, increment, decrement, and addition to calculate pixel coordinates and error values. It stores the result in a Java int array and paints selected coordinates with aset-int. section 5.14
Listing 5.11. → Integer math, Overflowing , More Use Cases
(unchecked-add-int [x y]) (unchecked-subtract-int [x y]) (unchecked-multiply-int [x y]) (unchecked-divide-int [x y]) (unchecked-inc-int [x]) (unchecked-dec-int [x]) (unchecked-negate-int [x]) (unchecked-remainder-int [x y])
Browse the complete unchecked-*-int operator family and its eight integer arithmetic operations. section 5.14














