Modify division behaviour to panic when dividing by 0, and add divChecked, divFloorChecked and divCeilingChecked` for safe alternatives which return a Result, mimicking the previous behaviour.

This commit is contained in:
Nikita Mounier 2022-04-11 11:23:33 +00:00
parent 23bc8aab49
commit 4ecf2a8c24
9 changed files with 318 additions and 129 deletions

View file

@ -310,9 +310,7 @@ pub const RocDec = extern struct {
// (n / 0) is an error
if (denominator_i128 == 0) {
// The compiler frontend does the `denominator == 0` check for us,
// therefore this case is unreachable from roc user code
unreachable;
@panic("TODO runtime exception for dividing by 0!");
}
// If they're both negative, or if neither is negative, the final answer