Ashton Wiersdorf
Ashton Wiersdorf

Reputation: 2020

How do I take the square root of a number in Elixir?

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

Answers (3)

Aleksandr Sysoev
Aleksandr Sysoev

Reputation: 199

Also, since Elixir version 1.13, you can use exponent syntax.

x ** 0.5

Upvotes: 2

user9982908
user9982908

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

Ashton Wiersdorf
Ashton Wiersdorf

Reputation: 2020

Hah. Found it. You take the square root like this:

:math.sqrt(x)

Upvotes: 15

Related Questions