function | since v1.11.50 | Edit |
(subtract-exact x y)
Returns the difference of x and y, throws ArithmeticException on overflow.
(defn ^number subtract-exact
{:added "1.11.10"}
[x y]
(let [r (- x y)]
(if (or (> r js/Number.MAX_SAFE_INTEGER) (< r js/Number.MIN_SAFE_INTEGER))
(throw (ex-info "Integer overflow" {:fn "subtract-exact"}))
r)))