Reputation: 2020
How do I take the square root of a number in Elixir? There doesn't seem to be a Math
module or anything, and there is no function like sqrt()
.
Upvotes: 26
Views: 9774
Reputation: 199
Also, since Elixir version 1.13, you can use exponent syntax.
x ** 0.5
Upvotes: 2
Reputation:
Elixir compiles to BEAM, which makes it compatible with Erlang modules. As you said, :math.sqrt(x)
is essentially running Erlang code.
Upvotes: 31
Reputation: 2020
Hah. Found it. You take the square root like this:
:math.sqrt(x)
Upvotes: 15