Stream: compiler development

Topic: Num.shiftRightZfBy issue?


view this post on Zulip Aurélien Geron (Oct 16 2024 at 02:47):

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?

view this post on Zulip Brendan Hansknecht (Oct 16 2024 at 02:50):

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.

view this post on Zulip Aurélien Geron (Oct 16 2024 at 02:50):

Oh great, I had just started writing a message about that!

view this post on Zulip Aurélien Geron (Oct 16 2024 at 02:52):

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