Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

javascript

elm

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?

like image 427
IzumiSy Avatar asked Jul 30 '19 14:07

IzumiSy


1 Answers

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.

like image 197
toastifer Avatar answered Sep 29 '22 02:09

toastifer