Package de.tilman_neumann.jml.roots
Class SqrtInt
- java.lang.Object
-
- de.tilman_neumann.jml.roots.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 Summary
Constructors Constructor Description SqrtInt()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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.static BigInteger[]iSqrt(BigInteger n, BigInteger guess)Simplest Heron-type sqrt() implementation.static voidmain(String[] args)Test.
-
-
-
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
-
-