elm/core

modBy gives runtime error when called with zero divident

decafbad opened this issue · 3 comments

Basics.modBy 0 3
Error: Cannot perform mod 0. Division by zero error.

Besides that, its sibling returns an impossible thing

Basic.remainderBy 0 3
NaN : Int

Actually, the 0 in Basics.modBy 0 3 is the divisor, not the dividend.

Also: #590, #721.

NaN : Int isn't ok for me. Thanks.

The fact that Basics.remainderBy returns NaN makes sense if you look at [its definition]
(https://github.com/elm/core/blob/master/src/Elm/Kernel/Basics.js#L17):

var _Basics_remainderBy = F2(function(b, a) { return a % b; });

I don't think this behaviour is intentional - as elm is compiled into (untyped) javascript such strange results as this will happen from time to time.


As an aside: if you do not feel scared enough by NaN : Int see #1003 for a way to get Infinity : Int 😨