Package edu.rit.util
Class Mathe
java.lang.Object
edu.rit.util.Mathe
Class Mathe provides useful mathematical operations. The class is named
"Mathe" so the compiler won't confuse it with class
org.apache.commons.math3.util.FastMath.
- Version:
- 11-Feb-2010
- Author:
- Alan Kaminsky
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
sqrt
(int x) Compute the integer square root of the integerx
.
-
Method Details
-
sqrt
public static int sqrt(int x) Compute the integer square root of the integerx
. The value floor(x
1/2) is returned. The answer is calculated using an exact integer algorithm taken from:- J. Crenshaw. Integer square roots. http://www.embedded.com/98/9802fe2.htm
- Parameters:
x
- Input.- Returns:
- Floor(
x
1/2). - Throws:
ArithmeticException
- (unchecked exception) Thrown ifx
< 0.
-