Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

elixir

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

For example, 23 would return 8.

like image 904
Nathan Long Avatar asked Aug 15 '15 11:08

Nathan Long


People also ask

What happens when you raise a number to a power?

When you "raise a number to a power," you're multiplying the number by itself, and the "power" represents how many times you do so. So 2 raised to the 3rd power is the same as 2 x 2 x 2, which equals 8.


1 Answers

Use the Erlang :math module

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

If you want an integer:

:math.pow(2,3) |> round #=> 8 
like image 50
Nathan Long Avatar answered Sep 28 '22 19:09

Nathan Long