Fork me on GitHub
#clojure-europe
<
2022-07-31
>
genRaiy11:07:24

good morning

genRaiy11:07:37

(bit-shift-right 1024 4)
=> 64
(/ 1024 16)
=> 64

pez13:07:27

bit-shift-right compiles to 1024 >> 4, while / often will invoke the Clojure runtime checking for ratios and overflow and whatnot. I can recommend inspecting the generated byte code to appreciate the difference. In this video I show the use of a decompiler on this particular example: https://m.youtube.com/watch?v=tRPKSXullYs

genRaiy13:07:33

(* 64 16)
=> 1024
(bit-shift-left 64 4)
=> 1024

genRaiy13:07:53

can there be any confusion on this one?

genRaiy13:07:24

that's a long video... what is the timing of the part where you inspect the byte code?

pez14:07:18

Checking it I'm not sure it even happens in that video. 😀 But in this one it does: https://youtu.be/T_wuPrHIupU Some 1 hour and 32 minutes in. And I think earlier than that too.

genRaiy18:07:39

Ha OK - I'll take a look

genRaiy11:07:44

in face of a JIT ... why would anyone use bit-shift-right ? Or is the JIT actually terrible?

slipset18:07:18

I guess if you’re working in the domain of bits, it might make more sense to bit shift the number of bits you want to shift rather than divide by some power of two?

😬 1