I propose to add a new operator, **
, to Elixir.
The default implementation in Kernel.**/2
will be arithmetic exponentiation. In this way, it will work similar to the **
in Python, Ruby, Haskell and a multitude of other languages.
When working with integers, the result will be calculated using the Exponentiation by Squaring algorithm, returning an integer. (or a float when using negative powers)
When working with floats, erlang's :math.pow/2
function is used, which returns a float. This second case can also be used to calculate roots (i.e. 2 ** 0.5
).
As :math.pow()
is not inside erlang's BIN functions (as well as the integer-implementation being built with functions, not macros), it is impossible to use the Kernel.**/2
in guard clauses.
I don't think this needs to be added to Kernel. Build a math library if you care to and put it on Hex.pm.
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/7873e9d7-26f0-4eb3-a6d4-7e1147f72d66%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/ca525245-bed9-4335-ad00-3d20d52066cc%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/ca525245-bed9-4335-ad00-3d20d52066cc%40googlegroups.com.
It actually was a definable operator but we removed it before 1.0 because one day we may implement ** and it would break everyone's usage of it. Generally it is risky to leave operators we would like to use in the future available because, when we eventually use them, it will break code.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAAPY6eMYWBoREGYS0tHFopQ64Khv0BHLX5-3zWpaL6s5eqTcRg%40mail.gmail.com.