ClojureDocs

Nav

Namespaces

unchecked-inc

clojure.core

Available since 1.0 (source)
  • (unchecked-inc x)
Returns a number one greater than x, a long.
Note - uses a primitive operator subject to overflow.
2 Examples
users=> (unchecked-inc Integer/MAX_VALUE)
-2147483648

users=> (unchecked-inc 0)
1
;; Illustrates the difference between (inc), (inc') and (unchecked-inc)

;; The "N" suffix denotes a BigInt instance
;; https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/BigInt.java

Long/MAX_VALUE
;;=> 9223372036854775807

(inc Long/MAX_VALUE)
;;=> ArithmeticException integer overflow  clojure.lang.Numbers.throwIntOverflow (Numbers.java:1501)

(inc' Long/MAX_VALUE)
;;=> 9223372036854775808N

;; Notice how the resulting number becomes NEGATIVE:
(unchecked-inc Long/MAX_VALUE)
;;=> -9223372036854775808
See Also

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

Added by boxie

Returns a number one less than x, a long. Note - uses a primitive operator subject to overflow.

Added by boxie

Returns a number one greater than x, a long. Note - uses a primitive operator subject to overflow.

Added by boxie

Returns the negation of x, a long. Note - uses a primitive operator subject to overflow.

Added by boxie

Returns the difference of x and y, both long. Note - uses a primitive operator subject to overflow...

Added by boxie

Returns the product of x and y, both long. Note - uses a primitive operator subject to overflow.

Added by boxie

Returns a number one greater than num. Does not auto-promote longs, will throw on overflow. See al...

Added by svenschoenung

Returns a number one greater than num. Supports arbitrary precision. See also: inc

Added by svenschoenung
0 Notes
No notes for unchecked-inc