I’m playing around with various core bit shift functions (e.g., bit-shift-left, bit-shift-right) and wanted to check some assumptions. It appears that with these bitwise instructions, ClojureScript is manipulating an implicit 32-bit signed quantity. For instance:
cljs.user=> (bit-shift-left 1 30)
1073741824
cljs.user=> (bit-shift-left 1 31)
-2147483648
And then the shift amount is modulo 32, so
cljs.user=> (bit-shift-left 1 32)
1
cljs.user=> (bit-shift-left 1 33)
2
cljs.user=> (bit-shift-left 1 34)
4
I can’t find this documented anywhere in the ClojureScript API docs, though. Clojure JVM uses a 64-bit field and the shift amount is modulo 64. I assume ClojureScript can’t use 64 bits because all numbers are doubles and so that would exceed the precision of a double and cause problems. Is all that correct?This is because of how these operations work in javascript, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_AND.
> For numbers, the operator returns a 32-bit integer.
Perfect, thanks.