Class SqrtInt

java.lang.Object
de.tilman_neumann.jml.roots.SqrtInt

public class SqrtInt
extends java.lang.Object
Fast sqrt() computation with integer solutions using Herons (or "Babylonian") method and the built-in Math.sqrt() as initial guess.
  • Constructor Summary

    Constructors
    Constructor Description
    SqrtInt()  
  • Method Summary

    Modifier and Type Method Description
    static java.math.BigInteger[] iSqrt​(java.math.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.
    static java.math.BigInteger[] iSqrt​(java.math.BigInteger n, java.math.BigInteger guess)
    Simplest Heron-type sqrt() implementation.
    static void main​(java.lang.String[] args)
    Test.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SqrtInt

      public SqrtInt()
  • Method Details

    • iSqrt

      public static java.math.BigInteger[] iSqrt​(java.math.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 java.math.BigInteger[] iSqrt​(java.math.BigInteger n, java.math.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​(java.lang.String[] args)
      Test.
      Parameters:
      args - ignored