Class XMath
public final class XMath extends Object
- 
Constructor SummaryConstructors Constructor Description XMath()
- 
Method SummaryModifier and Type Method Description static longaddCapped(long l1, long l2)static doubleavg(double... values)static floatavg(float... values)static intavg(int... values)static longavg(long... values)static BigDecimalbigDec(double value)Alias forBigDecimal.valueOf(value)static BigDecimalbigDec(long value)Alias forBigDecimal.valueOf(value)static BigIntegerbigInt(int value)Alias forBigInteger.valueOf(value)static BigIntegerbigInt(long value)Alias forBigInteger.valueOf(value)static intcap_int(long value)static double[]column(int columnIndex, double[]... matrix)static doublecolumnSum(int columnIndex, double[]... matrix)static doublecolumnSum(int columnIndex, Double[]... matrix)static doublecube(double d)static floatcube(float f)static intcube(int i)static longcube(long l)static longequal(long value1, long value2)static inteven(int value)static longeven(long value)static intfactorial(int n)Usefactorial(long)for n in [0;20].
 Usefactorial(BigInteger)for any n greater than 0.static longfactorial(long n)Usefactorial(BigInteger)for any n greater than 0.static BigIntegerfactorial(BigInteger n)static doublefractionToPercent(double decimalFractionValue)static inthighestPowerOf2_int()static booleanisGreaterThanHighestPowerOf2(int value)static booleanisGreaterThanHighestPowerOf2(long value)static booleanisGreaterThanOrEqualHighestPowerOf2(int value)static booleanisGreaterThanOrEqualHighestPowerOf2(long value)static booleanisIn(int value, int... searchValues)static booleanisPow2(int value)Determines if the passed value is a power-of-2 value.static intlog10discrete(int value)Returns the integer value of base-10 logarithm of the passed value.static intlog2pow2(int pow2Value)static doublelowerRatio(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 doublemax(double... values)static floatmax(float... values)static intmax(int... values)static longmax(long... values)static doublemin(double... values)static floatmin(float... values)static intmin(int... values)static longmin(long... values)static <E> doublemin_double(Iterable<E> elements, To_double<? super E> getter)static <E> doublemin_double(Iterable<E> elements, To_double<? super E> getter, double defaultValue)static <E> DoubleminDouble(Iterable<E> elements, To_double<? super E> getter)static intnegative(int value)static longnegative(long value)static doublenotNegative(double value)static intnotNegative(int value)static longnotNegative(long value)static IntegernotNegative(Integer value)static LongnotNegative(Long value)static doublenotNegativeMax1(double value)static intodd(int value)static longodd(long value)static Doubleone()static doublepercentToFraction(double decimalPercentValue)static doublepositive(double value)static floatpositive(float value)static intpositive(int value)static longpositive(long value)static doublepositiveMax1(double value)static doublepow(double base, int exponent)static floatpow(float base, int exponent)static intpow(int base, int exponent)This method is an int version ofMath.pow(double, double), using only integer iteration for calculation.static intpow10(int exponent)static doublepow10_double(int exponent)static longpow10_long(int exponent)static intpow2Bound(int n)static intpow2BoundCapped(int n)static intpow2BoundMaxed(int n)static Randomrandom()static intrandom(int n)static int[]randoming(int length)static int[]randoming(int length, int bound)static int[]randoming(int length, int lowestValue, int bound)static _longRangerange(int start, int bound)static doubleround(double value, int decimals)Roundsvalueto the actual closest value fordecimalsdecimals.
 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 doubleround0(double value)static doubleround1(double value)Common rounding variant for 1 decimal.static doubleround2(double value)Common rounding variant for 2 decimals.static doubleround3(double value)Common rounding variant for 3 decimals.static doubleround4(double value)Common rounding variant for 4 decimals.static doubleround5(double value)Common rounding variant for 5 decimals.static doubleround6(double value)Common rounding variant for 6 decimals.static doubleround7(double value)Common rounding variant for 7 decimals.static doubleround8(double value)Common rounding variant for 8 decimals.static doubleround9(double value)Common rounding variant for 9 decimals.static byte[]sequence(byte from, byte to)static int[]sequence(int lastValue)static int[]sequence(int from, int to)static long[]sequence(long from, long to)static short[]sequence(short from, short to)static Integer[]sequence(Integer lastValue)static doublesquare(double d)static floatsquare(float f)static intsquare(int i)static longsquare(long l)static intstringLength(int value)Returns the amount of digits the passed values requires to be projected as a string.static longsum(byte... values)static doublesum(double... values)static doublesum(float... values)static longsum(int... values)static longsum(long... values)static longsum(short... values)static Doublezero()
- 
Constructor Details- 
XMathpublic XMath()
 
- 
- 
Method Details- 
zero
- 
one
- 
powThis method is an int version ofMath.pow(double, double), using only integer iteration for calculation.As a rule of thumb: 
 It is faster forexponentlower than 250 (significantly faster for exponents lt 100) and slower forexponentgreater than or equal 250 (significantly slower for exponents gt/e 500).
 This may depend on the concrete system running the program, of course.
 Note thatexponentmay not be negative, otherwise anIllegalArgumentExceptionis thrown.- Parameters:
- base-
- exponent- my not be negative
- Returns:
- base^exponent
- Throws:
- IllegalArgumentException- if- exponentis negative
 
- 
pow10- Throws:
- IllegalArgumentException
 
- 
pow10_double- Throws:
- IllegalArgumentException
 
- 
pow10_long- Throws:
- IllegalArgumentException
 
- 
pow2BoundMaxedpublic static final int pow2BoundMaxed(int n)
- 
pow2BoundCappedpublic static final int pow2BoundCapped(int n)
- 
pow2Boundpublic static final int pow2Bound(int n)
- 
log2pow2public static final int log2pow2(int pow2Value)
- 
isPow2public static final boolean isPow2(int value)Determines if the passed value is a power-of-2 value.- Parameters:
- value- the value to be tested.
- Returns:
- truefor any n in [0;30] that satisfies- value = 2^n.
 
- 
log10discreteReturns the integer value of base-10 logarithm of the passed value.Examples: log10(1) = 0 log10(8) = 0 log10(10) = 1 log10(99) = 1 log10(100) = 2 log10(1000000000) = 9 log10(2147483647) = 9 IllegalArgumentException.- Parameters:
- value-
- Throws:
- IllegalArgumentException
 
- 
stringLengthpublic static final int stringLength(int value)Returns the amount of digits the passed values requires to be projected as a string.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 - Parameters:
- value- the- intvalue whose string length shall be calculated
- Returns:
- the length the passed value's string representation will require.
 
- 
pow- Throws:
- IllegalArgumentException
 
- 
pow- Throws:
- IllegalArgumentException
 
- 
squarepublic static final float square(float f)
- 
squarepublic static final long square(long l)
- 
squarepublic static final int square(int i)
- 
squarepublic static final double square(double d)
- 
cubepublic static final float cube(float f)
- 
cubepublic static final long cube(long l)
- 
cubepublic static final int cube(int i)
- 
cubepublic static final double cube(double d)
- 
round0public static final double round0(double value)
- 
round1public static final double round1(double value)Common rounding variant for 1 decimal.- Parameters:
- value- the decimal value to be rounded.
- Returns:
- the passed value rounded to 1 decimal.
 
- 
round2public static final double round2(double value)Common rounding variant for 2 decimals.- Parameters:
- value- the decimal value to be rounded.
- Returns:
- the passed value rounded to 2 decimals.
 
- 
round3public static final double round3(double value)Common rounding variant for 3 decimals.- Parameters:
- value- the decimal value to be rounded.
- Returns:
- the passed value rounded to 3 decimals.
 
- 
round4public static final double round4(double value)Common rounding variant for 4 decimals.- Parameters:
- value- the decimal value to be rounded.
- Returns:
- the passed value rounded to 4 decimals.
 
- 
round5public static final double round5(double value)Common rounding variant for 5 decimals.- Parameters:
- value- the decimal value to be rounded.
- Returns:
- the passed value rounded to 5 decimals.
 
- 
round6public static final double round6(double value)Common rounding variant for 6 decimals.- Parameters:
- value- the decimal value to be rounded.
- Returns:
- the passed value rounded to 6 decimals.
 
- 
round7public static final double round7(double value)Common rounding variant for 7 decimals.- Parameters:
- value- the decimal value to be rounded.
- Returns:
- the passed value rounded to 7 decimals.
 
- 
round8public static final double round8(double value)Common rounding variant for 8 decimals.- Parameters:
- value- the decimal value to be rounded.
- Returns:
- the passed value rounded to 8 decimals.
 
- 
round9public static final double round9(double value)Common rounding variant for 9 decimals.- Parameters:
- value- the decimal value to be rounded.
- Returns:
- the passed value rounded to 9 decimals.
 
- 
roundpublic static final double round(double value, int decimals)Roundsvalueto the actual closest value fordecimalsdecimals.
 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.Note that decimalsmay not be negative.
 Also note that while a value of 0 fordecimalswill yield the correct result, it makes not much sense to call this method for it in the first place.- Parameters:
- value- any double value
- decimals- the number of decimals. May not be negative.
- Returns:
- the normalized value for value
 
- 
range
- 
sequencepublic static byte[] sequence(byte from, byte to)
- 
sequencepublic static short[] sequence(short from, short to)
- 
sequencepublic static int[] sequence(int lastValue)
- 
randomingpublic static int[] randoming(int length)
- 
randomingpublic static int[] randoming(int length, int bound)
- 
randomingpublic static int[] randoming(int length, int lowestValue, int bound)
- 
sequence
- 
sequencepublic static int[] sequence(int from, int to)
- 
sequence- Throws:
- IllegalArgumentException
 
- 
maxpublic static final double max(double... values)
- 
maxpublic static final float max(float... values)
- 
maxpublic static final int max(int... values)
- 
maxpublic static final long max(long... values)
- 
minpublic static final double min(double... values)
- 
minpublic static final float min(float... values)
- 
minpublic static final int min(int... values)
- 
minpublic static final long min(long... values)
- 
sumpublic static final long sum(byte... values)
- 
sumpublic static final long sum(short... values)
- 
sumpublic static final long sum(int... values)
- 
sumpublic static final double sum(float... values)
- 
sumpublic static final long sum(long... values)
- 
sumpublic static final double sum(double... values)
- 
columnSumpublic static final double columnSum(int columnIndex, double[]... matrix)
- 
columnSum
- 
avgpublic static final double avg(double... values)
- 
avgpublic static final float avg(float... values)
- 
avgpublic static final int avg(int... values)
- 
avgpublic static final long avg(long... values)
- 
lowerRatiopublic static final 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]- Parameters:
- a- the first value
- b- the second value
- Returns:
- the lower ratio of d1 and d2
 
- 
factorialUsefactorial(long)for n in [0;20].
 Usefactorial(BigInteger)for any n greater than 0.- Parameters:
- n- natural number in [0;12]
- Returns:
- n!
- Throws:
- IllegalArgumentException- for n lower than 0 or n greater than 12.
 
- 
factorialUsefactorial(BigInteger)for any n greater than 0.- Parameters:
- n- natural number in [0;20]
- Returns:
- n!
- Throws:
- IllegalArgumentException- for n lower than 0 or n greater than 20
 
- 
factorial- Parameters:
- n- any natural number greater than or equal 0
- Returns:
- n!
- Throws:
- IllegalArgumentException- for n lower than 0
 
- 
bigIntAlias forBigInteger.valueOf(value)- Parameters:
- value- any value
- Returns:
- a BigIntegerrepresentingvalue
 
- 
bigIntAlias forBigInteger.valueOf(value)- Parameters:
- value- any value
- Returns:
- a BigIntegerrepresentingvalue
 
- 
bigDecAlias forBigDecimal.valueOf(value)- Parameters:
- value- any value
- Returns:
- a BigDecimalrepresentingvalue
 
- 
bigDecAlias forBigDecimal.valueOf(value)- Parameters:
- value- any value
- Returns:
- a BigDecimalrepresentingvalue
 
- 
random- Returns:
- the random
 
- 
randompublic static final int random(int n)
- 
evenpublic static int even(int value)
- 
evenpublic static long even(long value)
- 
oddpublic static int odd(int value)
- 
oddpublic static long odd(long value)
- 
positive- Throws:
- NumberRangeException
 
- 
notNegative- Throws:
- NumberRangeException
 
- 
notNegative- Throws:
- NumberRangeException
 
- 
negative- Throws:
- NumberRangeException
 
- 
positive- Throws:
- NumberRangeException
 
- 
notNegative- Throws:
- NumberRangeException
 
- 
notNegative- Throws:
- NumberRangeException
 
- 
negative- Throws:
- NumberRangeException
 
- 
positive- Throws:
- NumberRangeException
 
- 
notNegative- Throws:
- NumberRangeException
 
- 
positiveMax1- Throws:
- NumberRangeException
 
- 
notNegativeMax1- Throws:
- NumberRangeException
 
- 
positive- Throws:
- NumberRangeException
 
- 
equal- Throws:
- IllegalArgumentException
 
- 
columnpublic static double[] column(int columnIndex, double[]... matrix)
- 
cap_intpublic static final int cap_int(long value)
- 
isGreaterThanOrEqualHighestPowerOf2public static final boolean isGreaterThanOrEqualHighestPowerOf2(long value)
- 
isGreaterThanHighestPowerOf2public static final boolean isGreaterThanHighestPowerOf2(long value)
- 
isGreaterThanOrEqualHighestPowerOf2public static final boolean isGreaterThanOrEqualHighestPowerOf2(int value)
- 
isGreaterThanHighestPowerOf2public static final boolean isGreaterThanHighestPowerOf2(int value)
- 
highestPowerOf2_intpublic static final int highestPowerOf2_int()
- 
fractionToPercentpublic static final double fractionToPercent(double decimalFractionValue)
- 
percentToFractionpublic static final double percentToFraction(double decimalPercentValue)
- 
isInpublic static final boolean isIn(int value, int... searchValues)
- 
addCappedpublic static long addCapped(long l1, long l2)
- 
minDouble
- 
min_double
- 
min_double
 
-