gleam/int.power(Int, Int) -> Int & gleam/float.power(Float, Float) -> Float #3320
-
Im trying to calculate a value of a base raised to the power of n where all the values are known integers. the current implementation makes that really cumbersome and clunky. my particular use case is Exercism's Armstrong Numbers the obvious reason for differentiating gleam/int.power and gleam/float.power being the first argument it the aforementioned type. I would have expected the function in a given module to handle that value type. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Hello! It is not possible to implement int.power as returning an int as that mathematical operation does not always return a whole number. It is also not possible to have it always return a float as there are numbers for which it is not defined. |
Beta Was this translation helpful? Give feedback.
-
Thank you for taking time to respond. |
Beta Was this translation helpful? Give feedback.
-
I have encountered this same problem/challenge in more than one Exercism puzzle, so +1.
@lpil Do you mean that there exist such integers Note that the OP didn't propose changing the current Instead they proposed replacing it with these:
I agree this would be handy, unless there really are cases where |
Beta Was this translation helpful? Give feedback.
Hello! It is not possible to implement int.power as returning an int as that mathematical operation does not always return a whole number. It is also not possible to have it always return a float as there are numbers for which it is not defined.