unchecked-subtract

clojure.core

  • (unchecked-subtract x y)
Returns the difference 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
    ;; overflow very easily as shown below.
    
    (unchecked-subtract Long/MIN_VALUE 5555555554)
    user=> 9223372031299220254
    
    (unchecked-subtract Long/MIN_VALUE 1)
    user=> java.lang.IllegalArgumentException: No matching method found: unchecked_subtract (NO_SOURCE_FILE:0)
    
    (unchecked-subtract Long/MIN_VALUE Long/MIN_VALUE)
    user=> 0
    
    (unchecked-subtract Integer/MIN_VALUE Long/MIN_VALUE)
    user=> java.lang.IllegalArgumentException: No matching method found: unchecked_subtract (NO_SOURCE_FILE:0)
    
    (unchecked-subtract Integer/MIN_VALUE Integer/MIN_VALUE)
    user=> 0
    
    (unchecked-subtract Integer/MIN_VALUE 0)
    user=> -2147483648
    
    (unchecked-subtract Integer/MIN_VALUE 1)
    user=> 2147483647
    
    (unchecked-subtract Integer/MIN_VALUE 54444444)
    user=> 2093039204
    
    (unchecked-subtract 123456 654321)
    user=> -530865
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:1147 top

(defn unchecked-subtract
  "Returns the difference of x and y, both long.
  Note - uses a primitive operator subject to overflow."
  {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_minus ~x ~y)))
   :added "1.0"}
  [x y] (. clojure.lang.Numbers (unchecked_minus x y)))
Vars in clojure.core/unchecked-subtract:
Used in 0 other vars

Comments top

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