Stream: beginners

Topic: ✔ Undefined behavior for Num.rem


view this post on Zulip Kiryl Dziamura (Jan 28 2024 at 18:17):

Modulo operation (42 % 0) crashes instead of panicking (divison by zero (42 / 0) works as expected)

image.png

Not sure if a ticket has already been created

view this post on Zulip Brendan Hansknecht (Jan 28 2024 at 18:20):

would mean that the wasm dev backend is missing the check if it is in the web repl. If it is in the local repl, it also affects the native dev backend

view this post on Zulip Kiryl Dziamura (Jan 28 2024 at 18:27):

Locally it's

» 42 % 0

42 : Int *

which is not expected as well I think

view this post on Zulip Brendan Hansknecht (Jan 28 2024 at 18:28):

I guess that if what the CPU instruction does when you pass in zero.... Lol

view this post on Zulip Asher Mancinelli (Jan 29 2024 at 01:15):

Is behavior always defined in roc? I would think there would be some constant folding pass that catches this before the ast leaves the frontend if so.

view this post on Zulip Richard Feldman (Jan 29 2024 at 01:50):

this is just a bug - we didn't implement the check :big_smile:

view this post on Zulip Richard Feldman (Jan 29 2024 at 01:50):

the only optimizations we do are related to tail-calls, mutation, and memory management

view this post on Zulip Richard Feldman (Jan 29 2024 at 01:51):

we don't yet do any inlining, constant folding, etc. - those are all left to LLVM for the moment

view this post on Zulip Kiryl Dziamura (Jan 29 2024 at 10:31):

Filed an issue. The same for 42 // 0 btw
https://github.com/roc-lang/roc/issues/6459

view this post on Zulip Kiryl Dziamura (Jan 29 2024 at 16:15):

@Richard Feldman I saw you closed the ticket, but the fix was only for //, not for %.
Tho looking at the fix for divTrunc by Folkert, I think I can quickly replicate it for rem

So if you reopen the issue, please assign it to me, I've already started! :grinning_face_with_smiling_eyes:

view this post on Zulip Notification Bot (Jan 30 2024 at 16:54):

Kiryl Dziamura has marked this topic as resolved.


Last updated: Jul 06 2025 at 12:14 UTC