public final class XMath extends Object
| Modifier and Type | Method and Description |
|---|---|
static long |
addCapped(long l1,
long l2) |
static double |
avg(double... values) |
static float |
avg(float... values) |
static int |
avg(int... values) |
static long |
avg(long... values) |
static BigDecimal |
bigDec(double value)
Alias for
BigDecimal.valueOf(value) |
static BigDecimal |
bigDec(long value)
Alias for
BigDecimal.valueOf(value) |
static BigInteger |
bigInt(int value)
Alias for
BigInteger.valueOf(value) |
static BigInteger |
bigInt(long value)
Alias for
BigInteger.valueOf(value) |
static int |
cap_int(long value) |
static double[] |
column(int columnIndex,
double[]... matrix) |
static double |
columnSum(int columnIndex,
double[]... matrix) |
static double |
columnSum(int columnIndex,
Double[]... matrix) |
static double |
cube(double d) |
static float |
cube(float f) |
static int |
cube(int i) |
static long |
cube(long l) |
static long |
equal(long value1,
long value2) |
static int |
even(int value) |
static long |
even(long value) |
static BigInteger |
factorial(BigInteger n) |
static int |
factorial(int n)
Use
factorial(long) for n in [0;20].Use factorial(BigInteger) for any n greater than 0. |
static long |
factorial(long n)
Use
factorial(BigInteger) for any n greater than 0. |
static double |
fractionToPercent(double decimalFractionValue) |
static int |
highestPowerOf2_int() |
static boolean |
isGreaterThanHighestPowerOf2(int value) |
static boolean |
isGreaterThanHighestPowerOf2(long value) |
static boolean |
isGreaterThanOrEqualHighestPowerOf2(int value) |
static boolean |
isGreaterThanOrEqualHighestPowerOf2(long value) |
static boolean |
isIn(int value,
int... searchValues) |
static boolean |
isMathematicalInteger(double value) |
static boolean |
isPow2(int value)
Determines if the passed value is a power-of-2 value.
|
static int |
log10discrete(int value)
Returns the integer value of base-10 logarithm of the passed value.
|
static int |
log2pow2(int pow2Value) |
static double |
lowerRatio(double a,
double b)
Returns abs(d1/d2) for abs(d1) lower than abs(d2), else abs(d2/d1) in order to guarantee a codomain of [0.0;1.0]
|
static double |
max(double... values) |
static float |
max(float... values) |
static int |
max(int... values) |
static long |
max(long... values) |
static <E> double |
min_double(Iterable<E> elements,
To_double<? super E> getter) |
static <E> double |
min_double(Iterable<E> elements,
To_double<? super E> getter,
double defaultValue) |
static double |
min(double... values) |
static float |
min(float... values) |
static int |
min(int... values) |
static long |
min(long... values) |
static <E> Double |
minDouble(Iterable<E> elements,
To_double<? super E> getter) |
static int |
negative(int value) |
static long |
negative(long value) |
static double |
notNegative(double value) |
static int |
notNegative(int value) |
static Integer |
notNegative(Integer value) |
static long |
notNegative(long value) |
static Long |
notNegative(Long value) |
static double |
notNegativeMax1(double value) |
static int |
odd(int value) |
static long |
odd(long value) |
static Double |
one() |
static double |
percentToFraction(double decimalPercentValue) |
static double |
positive(double value) |
static float |
positive(float value) |
static int |
positive(int value) |
static long |
positive(long value) |
static double |
positiveMax1(double value) |
static double |
pow(double base,
int exponent) |
static float |
pow(float base,
int exponent) |
static int |
pow(int base,
int exponent)
This method is an int version of
Math.pow(double, double),
using only integer iteration for calculation. |
static double |
pow10_double(int exponent) |
static long |
pow10_long(int exponent) |
static int |
pow10(int exponent) |
static int |
pow2Bound(int n) |
static int |
pow2BoundCapped(int n) |
static int |
pow2BoundMaxed(int n) |
static Random |
random() |
static int |
random(int n) |
static int[] |
randoming(int length) |
static int[] |
randoming(int length,
int bound) |
static int[] |
randoming(int length,
int lowestValue,
int bound) |
static _longRange |
range(int start,
int bound) |
static double |
round(double value,
int decimals)
Rounds
value to the actual closest value for decimals decimals.This is useful as well in order to "normalize" values if multiple subsequent calulations with double values accumulate rounding errors that drift the value away from the value it actually should (could) be. See the "candy" example in Joshua Bloch's "Effective Java": this method fixes the problem. |
static double |
round0(double value) |
static double |
round1(double value)
Common rounding variant for 1 decimal.
|
static double |
round2(double value)
Common rounding variant for 2 decimals.
|
static double |
round3(double value)
Common rounding variant for 3 decimals.
|
static double |
round4(double value)
Common rounding variant for 4 decimals.
|
static double |
round5(double value)
Common rounding variant for 5 decimals.
|
static double |
round6(double value)
Common rounding variant for 6 decimals.
|
static double |
round7(double value)
Common rounding variant for 7 decimals.
|
static double |
round8(double value)
Common rounding variant for 8 decimals.
|
static double |
round9(double value)
Common rounding variant for 9 decimals.
|
static byte[] |
sequence(byte from,
byte to) |
static int[] |
sequence(int lastValue) |
static Integer[] |
sequence(Integer lastValue) |
static int[] |
sequence(int from,
int to) |
static long[] |
sequence(long from,
long to) |
static short[] |
sequence(short from,
short to) |
static double |
square(double d) |
static float |
square(float f) |
static int |
square(int i) |
static long |
square(long l) |
static int |
stringLength(int value)
Returns the amount of digits the passed values requires to be projected as a string.
|
static long |
sum(byte... values) |
static double |
sum(double... values) |
static double |
sum(float... values) |
static long |
sum(int... values) |
static long |
sum(long... values) |
static long |
sum(short... values) |
static Double |
zero() |
public static Double zero()
public static Double one()
public static final int pow(int base,
int exponent)
throws IllegalArgumentException
Math.pow(double, double),
using only integer iteration for calculation.
As a rule of thumb:
It is faster for exponent lower than 250 (significantly faster for exponents lt 100)
and slower for exponent greater than or equal 250 (significantly slower for exponents gt/e 500).
This may depend on the concrete system running the program, of course.
Note that exponent may not be negative, otherwise an IllegalArgumentException is
thrown.
base - the baseexponent - my not be negativebase^exponentIllegalArgumentException - if exponent is negativepublic static final int pow10(int exponent)
throws IllegalArgumentException
IllegalArgumentExceptionpublic static final double pow10_double(int exponent)
throws IllegalArgumentException
IllegalArgumentExceptionpublic static final long pow10_long(int exponent)
throws IllegalArgumentException
IllegalArgumentExceptionpublic static final int pow2BoundMaxed(int n)
public static final int pow2BoundCapped(int n)
public static final int pow2Bound(int n)
public static final int log2pow2(int pow2Value)
public static final boolean isPow2(int value)
value - the value to be tested.true for any n in [0;30] that satisfies value = 2^n.public static final int log10discrete(int value)
throws IllegalArgumentException
Examples:
log10(1) = 0 log10(8) = 0 log10(10) = 1 log10(99) = 1 log10(100) = 2 log10(1000000000) = 9 log10(2147483647) = 9Note that passing a value lower than or equal 0 will throw an
IllegalArgumentException.value - the value to calculate the logarithm onIllegalArgumentExceptionpublic static final int stringLength(int value)
The additional length for the minus of to represent negative values is acounted for as well.
Examples:
stringLength(0) = 1 stringLength(+6) = 1 stringLength(10) = 2 stringLength(+2147483647) = 10 stringLength(-1) = 2 stringLength(-2147483648) = 11
value - the int value whose string length shall be calculatedpublic static final float pow(float base,
int exponent)
throws IllegalArgumentException
IllegalArgumentExceptionpublic static final double pow(double base,
int exponent)
throws IllegalArgumentException
IllegalArgumentExceptionpublic static final float square(float f)
public static final long square(long l)
public static final int square(int i)
public static final double square(double d)
public static final float cube(float f)
public static final long cube(long l)
public static final int cube(int i)
public static final double cube(double d)
public static final double round0(double value)
public static final double round1(double value)
value - the decimal value to be rounded.public static final double round2(double value)
value - the decimal value to be rounded.public static final double round3(double value)
value - the decimal value to be rounded.public static final double round4(double value)
value - the decimal value to be rounded.public static final double round5(double value)
value - the decimal value to be rounded.public static final double round6(double value)
value - the decimal value to be rounded.public static final double round7(double value)
value - the decimal value to be rounded.public static final double round8(double value)
value - the decimal value to be rounded.public static final double round9(double value)
value - the decimal value to be rounded.public static final double round(double value,
int decimals)
value to the actual closest value for decimals decimals.
Note that decimals may not be negative.
Also note that while a value of 0 for decimals will yield the correct result, it makes not much
sense to call this method for it in the first place.
value - any double valuedecimals - the number of decimals. May not be negative.valuepublic static _longRange range(int start, int bound)
public static byte[] sequence(byte from,
byte to)
public static short[] sequence(short from,
short to)
public static int[] sequence(int lastValue)
public static int[] randoming(int length)
public static int[] randoming(int length,
int bound)
public static int[] randoming(int length,
int lowestValue,
int bound)
public static int[] sequence(int from,
int to)
public static long[] sequence(long from,
long to)
throws IllegalArgumentException
IllegalArgumentExceptionpublic static final double max(double... values)
public static final float max(float... values)
public static final int max(int... values)
public static final long max(long... values)
public static final double min(double... values)
public static final float min(float... values)
public static final int min(int... values)
public static final long min(long... values)
public static final long sum(byte... values)
public static final long sum(short... values)
public static final long sum(int... values)
public static final double sum(float... values)
public static final long sum(long... values)
public static final double sum(double... values)
public static final double columnSum(int columnIndex,
double[]... matrix)
public static final double columnSum(int columnIndex,
Double[]... matrix)
public static final double avg(double... values)
public static final float avg(float... values)
public static final int avg(int... values)
public static final long avg(long... values)
public static final double lowerRatio(double a,
double b)
a - the first valueb - the second valuepublic static final int factorial(int n)
throws IllegalArgumentException
factorial(long) for n in [0;20].factorial(BigInteger) for any n greater than 0.n - natural number in [0;12]IllegalArgumentException - for n lower than 0 or n greater than 12.public static final long factorial(long n)
throws IllegalArgumentException
factorial(BigInteger) for any n greater than 0.n - natural number in [0;20]IllegalArgumentException - for n lower than 0 or n greater than 20public static final BigInteger factorial(BigInteger n) throws IllegalArgumentException
n - any natural number greater than or equal 0IllegalArgumentException - for n lower than 0public static final BigInteger bigInt(int value)
BigInteger.valueOf(value)value - any valueBigInteger representing valuepublic static final BigInteger bigInt(long value)
BigInteger.valueOf(value)value - any valueBigInteger representing valuepublic static final BigDecimal bigDec(long value)
BigDecimal.valueOf(value)value - any valueBigDecimal representing valuepublic static final BigDecimal bigDec(double value)
BigDecimal.valueOf(value)value - any valueBigDecimal representing valuepublic static final Random random()
public static final int random(int n)
public static int even(int value)
public static long even(long value)
public static int odd(int value)
public static long odd(long value)
public static int positive(int value)
throws NumberRangeException
NumberRangeExceptionpublic static int notNegative(int value)
throws NumberRangeException
NumberRangeExceptionpublic static Integer notNegative(Integer value) throws NumberRangeException
NumberRangeExceptionpublic static int negative(int value)
throws NumberRangeException
NumberRangeExceptionpublic static long positive(long value)
throws NumberRangeException
NumberRangeExceptionpublic static long notNegative(long value)
throws NumberRangeException
NumberRangeExceptionpublic static Long notNegative(Long value) throws NumberRangeException
NumberRangeExceptionpublic static long negative(long value)
throws NumberRangeException
NumberRangeExceptionpublic static double positive(double value)
throws NumberRangeException
NumberRangeExceptionpublic static double notNegative(double value)
throws NumberRangeException
NumberRangeExceptionpublic static double positiveMax1(double value)
throws NumberRangeException
NumberRangeExceptionpublic static double notNegativeMax1(double value)
throws NumberRangeException
NumberRangeExceptionpublic static float positive(float value)
throws NumberRangeException
NumberRangeExceptionpublic static long equal(long value1,
long value2)
throws IllegalArgumentException
IllegalArgumentExceptionpublic static double[] column(int columnIndex,
double[]... matrix)
public static final int cap_int(long value)
public static final boolean isGreaterThanOrEqualHighestPowerOf2(long value)
public static final boolean isGreaterThanHighestPowerOf2(long value)
public static final boolean isGreaterThanOrEqualHighestPowerOf2(int value)
public static final boolean isGreaterThanHighestPowerOf2(int value)
public static final int highestPowerOf2_int()
public static final double fractionToPercent(double decimalFractionValue)
public static final double percentToFraction(double decimalPercentValue)
public static final boolean isIn(int value,
int... searchValues)
public static long addCapped(long l1,
long l2)
public static <E> double min_double(Iterable<E> elements, To_double<? super E> getter, double defaultValue)
public static boolean isMathematicalInteger(double value)
Copyright © 2022 MicroStream Software. All rights reserved.