public final class MathUtils extends Object
Defines some mathematical routines which are needed in calendrical calculations.
| Modifier and Type | Method and Description |
|---|---|
static int |
floorDivide(int value,
int divisor)
Returns the largest lower limit of quotient.
|
static long |
floorDivide(long value,
int divisor)
|
static int |
floorModulo(int value,
int divisor)
Calculates the remainder based on
floorDivide(int, int). |
static int |
floorModulo(long value,
int divisor)
|
static int |
safeAdd(int op1,
int op2)
Sums up the numbers with range check.
|
static long |
safeAdd(long op1,
long op2)
Sums up the numbers with range check.
|
static int |
safeCast(long num)
Performs a safe type-cast to an int-primitive.
|
static int |
safeMultiply(int op1,
int op2)
Multiplies the numbers with range check.
|
static long |
safeMultiply(long op1,
long op2)
Multiplies the numbers with range check.
|
static int |
safeNegate(int value)
Inverts the number with range check.
|
static long |
safeNegate(long value)
Inverts the number with range check.
|
static int |
safeSubtract(int op1,
int op2)
Subtracts the numbers from each other with range check.
|
static long |
safeSubtract(long op1,
long op2)
Subtracts the numbers from each other with range check.
|
public static int safeCast(long num)
Performs a safe type-cast to an int-primitive.
num - long-primitiveArithmeticException - if int-range overflowspublic static int safeAdd(int op1,
int op2)
Sums up the numbers with range check.
op1 - first operandop2 - second operandArithmeticException - if int-range overflowspublic static long safeAdd(long op1,
long op2)
Sums up the numbers with range check.
op1 - first operandop2 - second operandArithmeticException - if long-range overflowspublic static int safeSubtract(int op1,
int op2)
Subtracts the numbers from each other with range check.
op1 - first operandop2 - second operandArithmeticException - if int-range overflowspublic static long safeSubtract(long op1,
long op2)
Subtracts the numbers from each other with range check.
op1 - first operandop2 - second operandArithmeticException - if long-range overflowspublic static int safeMultiply(int op1,
int op2)
Multiplies the numbers with range check.
op1 - first operandop2 - second operandArithmeticException - if int-range overflowspublic static long safeMultiply(long op1,
long op2)
Multiplies the numbers with range check.
op1 - first operandop2 - second operandArithmeticException - if long-range overflowspublic static int safeNegate(int value)
Inverts the number with range check.
value - value to be negated-valueArithmeticException - if int-range overflowspublic static long safeNegate(long value)
Inverts the number with range check.
value - value to be negated-valueArithmeticException - if long-range overflowspublic static int floorDivide(int value,
int divisor)
Returns the largest lower limit of quotient.
Examples:
floorDivide(2, 2) == 1floorDivide(1, 2) == 0floorDivide(0, 2) == 0floorDivide(-1, 2) == -1floorDivide(-2, 2) == -1floorDivide(-3, 2) == -2value - numeratordivisor - divisorpublic static long floorDivide(long value,
int divisor)
value - numeratordivisor - divisorpublic static int floorModulo(int value,
int divisor)
Calculates the remainder based on floorDivide(int, int).
Examples:
floorModulo(2, 2) == 0floorModulo(1, 2) == 1floorModulo(0, 2) == 0floorModulo(-1, 2) == 1floorModulo(-2, 2) == 0floorModulo(-3, 2) == 1value - numeratordivisor - divisorpublic static int floorModulo(long value,
int divisor)
value - numeratordivisor - divisorCopyright © 2014–2015. All rights reserved.