Cldr.Math.sqrt
You're seeing just the function
sqrt
, go back to Cldr.Math module for more information.
Calculates the square root of a Decimal number using Newton's method.
number
is an integer, float or Decimal. For integer and float,sqrt
is delegated to the erlang:math
module.
We convert the Decimal to a float and take its
:math.sqrt
only to get an initial estimate.
The means typically we are only two iterations from
a solution so the slight hack improves performance
without sacrificing precision.
Examples
iex> Cldr.Math.sqrt(Decimal.new(9))
#Decimal<3.0>
iex> Cldr.Math.sqrt(Decimal.new("9.869"))
#Decimal<3.141496458696078173887197038>