Returns the sum of x and y, both int or long.
Note - uses a primitive operator subject to overflow.
;; can't interchange INTs with LONGs, only F(int, int) or F(long, long) ;; F is a function, not an operator. ;; overflow very easily as shown below. user=> (unchecked-add Integer/MAX_VALUE 0) 2147483647 user=> (unchecked-add Integer/MAX_VALUE 1) -2147483648 user=> (unchecked-add Integer/MAX_VALUE Integer/MAX_VALUE) -2 user=> (unchecked-add Integer/MAX_VALUE Long/MAX_VALUE) java.lang.IllegalArgumentException: No matching method found: unchecked_add (NO_SOURCE_FILE:0) user=> (unchecked-add Integer/MAX_VALUE Long/MAX_VALUE) java.lang.IllegalArgumentException: No matching method found: unchecked_add (NO_SOURCE_FILE:0) user=> (unchecked-add Long/MAX_VALUE Long/MAX_VALUE) -2 user=> (unchecked-add 5 Long/MAX_VALUE) java.lang.IllegalArgumentException: No matching method found: unchecked_add (NO_SOURCE_FILE:0) user=> (unchecked-add 5555555555 Long/MAX_VALUE) -9223372031299220254
Returns the difference of x and y, both int or long. Note - uses a
Returns the product of x and y, both int or long. Note - uses a pri
Returns the remainder of division of x by y, both int or long. Note
(defn unchecked-add
"Returns the sum of x and y, both int or long.
Note - uses a primitive operator subject to overflow."
{:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_add ~x ~y)))
:added "1.0"}
[x y] (. clojure.lang.Numbers (unchecked_add x y)))
Comments top
No comments for unchecked-add. Log in to add a comment.