Class SqrtInt


  • public class SqrtInt
    extends Object
    Fast sqrt() computation with integer solutions using Herons (or "Babylonian") method and the built-in Math.sqrt() as initial guess.
    Author:
    Tilman Neumann
    • Constructor Detail

      • SqrtInt

        public SqrtInt()
    • Method Detail

      • iSqrt

        public static BigInteger[] iSqrt​(BigInteger N)
        sqrt() computation with integer solutions using Herons (or "Babylonian") method and the built-in Math.sqrt() as initial guess, for any argument size and avoiding BigDecimals.
        Parameters:
        N -
        Returns:
        [lower, upper] int values of sqrt(N)
      • iSqrt

        public static BigInteger[] iSqrt​(BigInteger n,
                                         BigInteger guess)
        Simplest Heron-type sqrt() implementation. Here we use guess - n/guess as convergence criterion, which is simple and correct.
        Parameters:
        n -
        guess - the initial guess
        Returns:
        [lower, upper] int values of sqrt(n)
      • main

        public static void main​(String[] args)
        Test.
        Parameters:
        args - ignored