Search code examples
elixir

How do I raise a number to a power in Elixir?


How can I calculate a number with an exponent in Elixir?

For example, 23 would return 8.


Solution

  • **/2

    As of Elixir 1.13, ** is available.

    > 2 ** 3 
    8
    

    Note: it returns a float if the exponent is less than 0.

    Documentation