unchecked-int

added
1.3

ns
clojure.core

type
function

(unchecked-int x)

Coerce to int. Subject to rounding or truncation.

                (unchecked-int 1)
;;=> 1
(unchecked-int 1N)
;;=> 1
(unchecked-int 1.1)
;;=> 1
(unchecked-int 1.9)
;;=> 1
(unchecked-int 5/3)
;;=> 1

(unchecked-int -1)
;;=> -1
(unchecked-int -1N)
;;=> -1
(unchecked-int -1.1)
;;=> -1
(unchecked-int -1.9)
;;=> -1
(unchecked-int -5/3)
;;=> -1

;;;; Note that (unchecked-int) does not range check its argument
;;;; so integer overflow or rounding may occur. 
;;;; Use (int) if you want to throw an exception in such cases.

(unchecked-int 2147483648)
;;=> -2147483648
(unchecked-int -2147483649)
;;=> 2147483647

(int 2147483648)
;;=> IllegalArgumentException Value out of range for int: 2147483648
(long -2147483649)
;;=> IllegalArgumentException Value out of range for int: -2147483649

(unchecked-int 1.0E9)
;;=> 1000000000
(unchecked-int 1.0E10)
;;=> 2147483647
(unchecked-int 1.0E11)
;;=> 2147483647

(int 1.0E9)
;;=> 1000000000
(int 1.0E10)
;;=> IllegalArgumentException Value out of range for int: 1.0E10
(int 1.0E11)
;;=> IllegalArgumentException Value out of range for int: 1.0E11