unchecked-short

added
1.3

ns
clojure.core

type
function

(unchecked-short x)

Coerce to short. Subject to rounding or truncation.

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

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

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

(unchecked-short 32768)
;;=> -32768
(unchecked-short -32769)
;;=> 32767

(short 32768)
;;=> IllegalArgumentException Value out of range for short: 32768
(short -32769)
;;=> IllegalArgumentException Value out of range for short: -32769

(unchecked-short 1.0E4)
;;=> 10000
(unchecked-short 1.0E5)
;;=> -31072

(short 1.0E4)
;;=> 10000
(short 1.0E5)
;;=> IllegalArgumentException Value out of range for short: 100000.0