Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've taken the liberty to add a new operator,
**, to Elixir. The default implementation inKernel.**/2is that of arithmetic exponentiation. In this way, it works similar to the**in Python, Ruby, Haskell and a multitude of other languages.When working with integers (of which the power has to be positive), the result will be calculated using the Exponentiation by Squaring algorithm, returning an integer.
When working with floats (or a negative integer as power), it uses erlang's
:math.pow/2function, and returns a float. This second case can also be used to calculate roots (i.e.2 ** 0.5).Unfortunately, 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 theKernel.**/2in guard clauses.As there were multiple places in the library and the test suite where
:math.pow/2was called directly, this has been changed to use the new operator.I seem to have been successful in adding this new operator to the parser.
:**'s value is as expected. The only problem that remains is that&Kernel.**/2is for some reason not dispatching properly. Can someone tell me what's going on here?Of course, I am very happy with any and all comments on how to make the code cleaner, as well as criticism on the provided functionality.
Happy Easter!
~Qqwy