elm/core

Exponentiation of negative `Int`s

Closed this issue · 1 comments

Hello,

I recently noticed that exponentiation of negative Ints can result in non-integral numbers with the type Int. For example:

> i = 10%4
2 : Int
> i
2 : Int
> -i
-2 : Int
> 10^(-i)
0.01 : Int

So, for instance, I could produce the following error on my elm-repl session:

> j = 2^(-i)
0.25 : Int
> k = 1/4
0.25 : Float
> j == k
(Type mismatch error)

I think 0.25 being an Int makes little sense, but I am not sure what would be the appropriate fix for this. The options I can think of are returning a number, returning a Float, and making such expressions illegal. The current implementation of (^) simply calls a native JS function and has type number -> number -> number.

Consolidated all the math related stuff into the #721 meta issue. Follow along there!