检查溢出

基本类型 / 数字 / 整型

;; + 检查范围,溢出时抛出异常,而不是悄悄回绕
(println
  (try (+ Long/MAX_VALUE 1)
       (catch ArithmeticException e (str "error: " (.getMessage e)))))

;; +'(以及 *'、-'、inc')溢出时提升为 BigInt,而不是抛出异常
(def promoted (+' Long/MAX_VALUE 1))
;; promoted is 9223372036854775808N
(println "promoted is" promoted (type promoted))

;; unchecked-add 会回绕,就像 C 那样
(println "wrapped is" (unchecked-add Long/MAX_VALUE 1))