Package com.couchbase.client.core.utils
Class MathUtils
java.lang.Object
com.couchbase.client.core.utils.MathUtils
public class MathUtils extends Object
Various math utility methods, also backports from later JDK versions.
- Since:
- 1.3.4
- Author:
- Michael Nitschinger
-
Constructor Summary
Constructors Constructor Description MathUtils()
-
Method Summary
-
Constructor Details
-
MathUtils
public MathUtils()
-
-
Method Details
-
floorMod
public static long floorMod(long x, long y)Backport of floorMod from the JDK since we need to support 1.6. Returns the largest (closest to positive infinity)long
value that is less than or equal to the algebraic quotient. There is one special case, if the dividend is the Long.MIN_VALUE and the divisor is-1
, then integer overflow occurs and the result is equal to theLong.MIN_VALUE
.Normal integer division operates under the round to zero rounding mode (truncation). This operation instead acts under the round toward negative infinity (floor) rounding mode. The floor rounding mode gives different results than truncation when the exact result is negative.
- Parameters:
x
- the dividendy
- the divisor- Returns:
- the largest (closest to positive infinity)
long
value that is less than or equal to the algebraic quotient. - Throws:
ArithmeticException
- if the divisory
is zero
-
floorDiv
public static long floorDiv(long x, long y)Backport of floorDiv from the JDK since we need to support 1.6. Returns the largest (closest to positive infinity)long
value that is less than or equal to the algebraic quotient. There is one special case, if the dividend is the Long.MIN_VALUE and the divisor is-1
, then integer overflow occurs and the result is equal to theLong.MIN_VALUE
.Normal integer division operates under the round to zero rounding mode (truncation). This operation instead acts under the round toward negative infinity (floor) rounding mode. The floor rounding mode gives different results than truncation when the exact result is negative.
- Parameters:
x
- the dividendy
- the divisor- Returns:
- the largest (closest to positive infinity)
long
value that is less than or equal to the algebraic quotient. - Throws:
ArithmeticException
- if the divisory
is zero- See Also:
floorMod(long, long)
-