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

Nathan Long picture Nathan Long · Aug 15, 2015 · Viewed 15.1k times · Source

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

For example, 23 would return 8.

Answer

Nathan Long picture Nathan Long · Aug 15, 2015

Use the Erlang :math module

:math.pow(2,3) #=> 8.0

If you want an integer:

:math.pow(2,3) |> round #=> 8