Search code examples
javascriptelm

Why does "remainderBy 0 100" in Elm 0.19 return NaN, not Maybe Int?


In JavaScript, 0 % 100 is 0, but in Elm, the result of the same operation is this.

> remainderBy 0 100
NaN : Int

I have just thought remainderBy function better returns Maybe Int like below.

> remainderBy 0 100
Nothing : Maybe Int

> remainderBy 6 3
Just 2 : Maybe Int

Does Elm have any reason why remainderBy returns NaN?


Solution

  • The first argument for remainderBy is the divisor, the opposite of what you expected. So remainderBy 0 100 is the same as 100 % 0

    You are dividing by 0, so the result is NaN.