unchecked-divide-int divides two numeric values as primitive 32-bit signed integers and returns an int. It belongs to Clojure’s unchecked-*-int family, which is useful when ordinary long-based arithmetic is unsuitable, such as integer algorithms and hashing. section 5.14
Its contract is:
- Takes two numeric arguments within the int range, from Integer/MIN_VALUE through Integer/MAX_VALUE. section 5.14
- Casts arguments to primitive int values and returns the primitive int result of the division. section 5.14
- Uses unchecked 32-bit arithmetic, so results overflow when they reach the limits of signed int precision. section 5.14
- Differs from unchecked-divide by retaining int precision rather than promoting the result to accommodate greater precision. section 5.14 section 5.4
Integer line drawing
A line-drawing routine uses `(unchecked-divide-int dx 2)` to initialize its integer error term, alongside unchecked subtraction and increment operations. This keeps coordinate and error calculations in the int-based representation used by a multidimensional Java image array. 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 compact listing of the eight unchecked int operators, including unchecked-divide-int. section 5.14
