crash on rem div by zero

This commit is contained in:
Kiryl Dziamura 2024-01-29 18:16:20 +01:00
parent dd86b11150
commit b3dfdb562b
No known key found for this signature in database
GPG key ID: FB539501A4561ACF
88 changed files with 554 additions and 534 deletions

View file

@ -1031,13 +1031,21 @@ divTruncUnchecked : Int a, Int a -> Int a
## Num.rem -8 -3
## ```
rem : Int a, Int a -> Int a
rem = \a, b ->
if Num.isZero b then
crash "Integer division by 0!"
else
Num.remUnchecked a b
remChecked : Int a, Int a -> Result (Int a) [DivByZero]
remChecked = \a, b ->
if Num.isZero b then
Err DivByZero
else
Ok (Num.rem a b)
Ok (Num.remUnchecked a b)
## traps (hardware fault) when given zero as the second argument.
remUnchecked : Int a, Int a -> Int a
isMultipleOf : Int a, Int a -> Bool