unchecked-add

clojure.core

  • (unchecked-add x y)
Returns the sum of x and y, both long.
Note - uses a primitive operator subject to overflow.

1 Example top

  • ;; 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
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:1133 top

(defn unchecked-add
  "Returns the sum of x and y, both 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)))
Vars in clojure.core/unchecked-add:
Used in 0 other vars

Comments top

No comments for unchecked-add. Log in to add a comment.