Package de.tilman_neumann.jml.roots
Class RootsReal
- java.lang.Object
-
- de.tilman_neumann.jml.roots.RootsReal
-
public class RootsReal extends Object
i.th root of floating point numbers. The current state-of-the-art is a Heron-style algorithm with a good initial guess derived from double computations. The Heron-style algorithm realizes the iteration formula x(k+1) = 1/n * ( (n-1) * x(k) + N/(x(k)^(n-1)) ), see {@link "https://en.wikipedia.org/wiki/Nth_root_algorithm"}.- Author:
- Tilman Neumann
-
-
Constructor Summary
Constructors Constructor Description RootsReal()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static BigDecimal
ithRoot(BigDecimal x, int i, Scale resultScale)
Compute i.th root of x.static BigDecimal
ithRoot(BigDecimal x, int i, BigDecimal guess, Scale resultScale)
Compute the i.th root with initial guess.static void
main(String[] argv)
Test.
-
-
-
Method Detail
-
ithRoot
public static BigDecimal ithRoot(BigDecimal x, int i, Scale resultScale)
Compute i.th root of x.- Parameters:
x
- argumenti
- the degree of the rootresultScale
- desired precision in after-comma digits- Returns:
- i.th root(x) with error < 0.5*10^-resultScale, i.e. resultScale decimal digits are rounded correctly
-
ithRoot
public static BigDecimal ithRoot(BigDecimal x, int i, BigDecimal guess, Scale resultScale)
Compute the i.th root with initial guess.- Parameters:
x
- argumenti
- degree of the rootguess
- initial guess of i.th root(x)resultScale
- desired precision in after-comma digits- Returns:
- i.th root(x) with error < 0.5*10^-resultScale, i.e. resultScale decimal digits are rounded correctly
-
main
public static void main(String[] argv)
Test.- Parameters:
argv
- command line arguments
-
-