public final class MathUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static double |
ROUNDED_LOG_PRECISION
Precision for rounded logarithm.
|
| Modifier and Type | Method and Description |
|---|---|
static int |
combinaison(int n,
int p)
it computes the number of combinaison C_n^p.
|
static int |
divCeil(int x,
int y)
Returns the smallest (closest to positive infinity)
int value that is greater or equal to a/b. |
static int |
divFloor(int x,
int y)
Returns the largest (closest to positive infinity)
int value that is less than or equal to a/b. |
static long |
factorial(int n)
simple recursive version of factorial
|
static boolean |
isPowerOfTwo(int x) |
static double |
log(double value,
double exponent) |
static int |
max(int[] values)
Returns the element with the greatest value in values.
|
static int |
max(int[][] values)
Returns the element with the greatest value in values.
|
static int |
min(int[] values)
Returns the element with the smallest value in values.
|
static int |
min(int[][] values)
Returns the element with the smallest value in values.
|
static int |
pow(int value,
int exp)
Returns the value of the first argument raised to the power of the
second argument.
|
static double |
roundedLog(double value,
double exponent)
a rounded logarithm to avoid issues with jvm dependant math functions
|
static int |
safeAdd(int x,
int y)
Returns the sum of its arguments,
returning either
Integer.MAX_VALUE if the result overflows an int,
or Integer.MIN_VALUE if the result underflows an int, . |
static int |
safeCast(long x) |
static int |
safeMultiply(int x,
int y)
Returns the product of its arguments,
returning either
Integer.MAX_VALUE if the result overflows an int,
or Integer.MIN_VALUE if the result underflows an int, . |
static int |
safeSubstract(int x,
int y)
Returns the difference of its arguments,
returning either
Integer.MAX_VALUE if the result overflows an int,
or Integer.MIN_VALUE if the result underflows an int, . |
static int |
sum(int[] values)
Returns the sum of elements in values.
|
static int |
sum(int[][] values)
Retuns the sum of elements in values.
|
static int |
sum(int[] values,
int begin,
int end)
Returns the sum of elements in values from position begin (inclusive) to position end (exclusive).
|
static int |
sumFrom(int[] values,
int begin)
Returns the sum of elements in values from position begin (inclusive) to values.length.
|
static int |
sumTo(int[] values,
int end)
Returns the sum of elements in values from position 0 (inclusive) to position end (exclusive).
|
public static final double ROUNDED_LOG_PRECISION
public static long factorial(int n)
n - size of the suitepublic static int combinaison(int n,
int p)
n - max cardinalityp - sub cardinalitypublic static boolean isPowerOfTwo(int x)
x - a valuepublic static int pow(int value,
int exp)
Math.pow(double, double) for special cases.value - exp - public static double log(double value,
double exponent)
public static double roundedLog(double value,
double exponent)
public static int sum(int[] values,
int begin,
int end)
values - array of intsbegin - starting position (inclusive)end - ending position (exclusive)public static int sumFrom(int[] values,
int begin)
values - array of intsbegin - starting position (inclusive)public static int sumTo(int[] values,
int end)
values - array of intsend - ending position (exclusive)public static int sum(int[] values)
values - array of intspublic static int sum(int[][] values)
values - matrix of intspublic static int max(int[] values)
values - array of intspublic static int max(int[][] values)
values - array of intspublic static int min(int[] values)
values - array of intspublic static int min(int[][] values)
values - array of intspublic static int divFloor(int x,
int y)
int value that is less than or equal to a/b.
Adapted from Math.floorDiv(int, int).x - the dividendy - the divisorint value that is less than or equal to a/b.public static int divCeil(int x,
int y)
int value that is greater or equal to a/b.
Adapted from Math.floorDiv(int, int).x - the dividendy - the divisorint value that is greater or equal to a/b.public static int safeAdd(int x,
int y)
Integer.MAX_VALUE if the result overflows an int,
or Integer.MIN_VALUE if the result underflows an int, .x - the first valuey - the second valuepublic static int safeSubstract(int x,
int y)
Integer.MAX_VALUE if the result overflows an int,
or Integer.MIN_VALUE if the result underflows an int, .x - the first valuey - the second valuepublic static int safeMultiply(int x,
int y)
Integer.MAX_VALUE if the result overflows an int,
or Integer.MIN_VALUE if the result underflows an int, .x - the first valuey - the second valuepublic static int safeCast(long x)
x - long to castCopyright © 2018. All rights reserved.