Package de.tilman_neumann.jml.roots
Class RootsReal
java.lang.Object
de.tilman_neumann.jml.roots.RootsReal
public class RootsReal
extends java.lang.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"}.
-
Constructor Summary
Constructors Constructor Description RootsReal()
-
Method Summary
Modifier and Type Method Description static java.math.BigDecimal
ithRoot(java.math.BigDecimal x, int i, Scale resultScale)
Compute i.th root of x.static java.math.BigDecimal
ithRoot(java.math.BigDecimal x, int i, java.math.BigDecimal guess, Scale resultScale)
Compute the i.th root with initial guess.static void
main(java.lang.String[] argv)
Test.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
RootsReal
public RootsReal()
-
-
Method Details
-
ithRoot
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 java.math.BigDecimal ithRoot(java.math.BigDecimal x, int i, java.math.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(java.lang.String[] argv)Test.- Parameters:
argv
- command line arguments
-