There seems to be an issue in the Roc REPL. It's simpler to just show it:
» (-8i8) |> Num.shiftRightZfBy 2
-2 : I8
This should return 62 : I8
instead. But surprisingly, if I use a def instead, it works fine:
» num = -8i8
-8 : I8
» num |> Num.shiftRightZfBy 2
62 : I8
Would you like me to open an issue on GitHub or is this known or somehow expected?
Personally, I think the real issue filed should be to delete shiftRightZfBy
and instead generate shift right based on if the number is signed or unsigned. I think shiftRightZfBy
was an interesting idea, but is more confusing than useful.
Oh great, I had just started writing a message about that!
I ran into this issue this morning because I used Num.shiftRightBy
(I hadn't noticed there was another function), and my code worked fine until one of the inputs was a bit too high and its most significant bit was 1. For lower values, my code was equivalent to n // 128
, but all of a sudden for large values is did something really strange. Switching to Num.shiftRightZfBy
fixed the problem.
Last updated: Jul 06 2025 at 12:14 UTC