;; Subtracting two int-range Longs works
(unchecked-subtract-int 1 1)
;;=> 0
;; Subtracting two int-range BigInts works
(unchecked-subtract-int 1N 1N)
;;=> 0
;; Doubles are truncated
(unchecked-subtract-int 1 1.9)
;;=> 0
;; BigDecimals are truncated
(unchecked-subtract-int 1 1.9M)
;;=> 0
;; Uncaught integer overflow
(unchecked-subtract-int Integer/MAX_VALUE -1)
;;=> -2147483648
;; Uncaught integer underflow
(unchecked-subtract-int Integer/MIN_VALUE 1)
;;=> 2147483647
;; Fails for Longs outside of int range
(unchecked-subtract-int 2147483648 0)
;;=> IllegalArgumentException Value out of range for int: 2147483648 clojure.lang.RT.intCast (RT.java:1205)
;; Fails for BigInts outside of int range
(unchecked-subtract-int 2147483648N 0)
;;=> IllegalArgumentException Value out of range for int: 2147483648 clojure.lang.RT.intCast (RT.java:1205)
;; Fails for Doubles outside of int range
(unchecked-subtract-int 2147483648.0 0)
;;=> IllegalArgumentException Value out of range for int: 2147483648 clojure.lang.RT.intCast (RT.java:1205)
;; Fails for BigDecimals outside of int range
(unchecked-subtract-int 2147483648.0M 0)
;;=> IllegalArgumentException Value out of range for int: 2147483648 clojure.lang.RT.intCast (RT.java:1205)