Class 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 Detail

      • RootsReal

        public RootsReal()
    • Method Detail

      • ithRoot

        public static BigDecimal ithRoot​(BigDecimal x,
                                         int i,
                                         Scale resultScale)
        Compute i.th root of x.
        Parameters:
        x - argument
        i - the degree of the root
        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
      • ithRoot

        public static BigDecimal ithRoot​(BigDecimal x,
                                         int i,
                                         BigDecimal guess,
                                         Scale resultScale)
        Compute the i.th root with initial guess.
        Parameters:
        x - argument
        i - degree of the root
        guess - 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