unchecked-byte

added
1.3

ns
clojure.core

type
function

(unchecked-byte x)

Coerce to byte. Subject to rounding or truncation.

                user=> (unchecked-byte 127)
127
user=> (unchecked-byte 128)
-128
user=> (unchecked-byte 255)
-1
user=> (unchecked-byte 256)
0
user=> (unchecked-byte 257)
1
            
                (unchecked-byte 1)
;;=> 1
(unchecked-byte 1N)
;;=> 1
(unchecked-byte 1.1)
;;=> 1
(unchecked-byte 1.9)
;;=> 1
(unchecked-byte 5/3)
;;=> 1

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

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

(unchecked-byte 128)
;;=> -128
(unchecked-byte -129)
;;=> 129

(byte 128)
;;=> IllegalArgumentException Value out of range for byte: 128
(byte -129)
;;=> IllegalArgumentException Value out of range for byte: -129

(unchecked-byte 1.0E2)
;;=> 100
(unchecked-byte 1.0E3)
;;=> -24

(byte 1.0E2)
;;=> 100
(byte 1.0E3)
;;=> IllegalArgumentException Value out of range for byte: 1000.0