Class MathUtil
- java.lang.Object
-
- de.uplanet.lucy.server.auxiliaries.MathUtil
-
@VelocityCallable("singleton") public final class MathUtil extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static intINT_MAX_VALUEstatic intINT_MIN_VALUEstatic longLONG_MAX_VALUEstatic longLONG_MIN_VALUE
-
Constructor Summary
Constructors Constructor Description MathUtil()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description doubleabs(double p_dblX)Returns the absolute value of a double value.floatabs(float p_fltX)Returns the absolute value of a float value.intabs(int p_iX)Returns the absolute value of an int value.longabs(long p_lX)Returns the absolute value of a long value.Numberadd(Number p_numL, Number p_numR)Adds two numbers.doubleceil(double p_dbl)Returns the smallest double value that is greater than or equal to the argument and is equal to a mathematical integer.doublecircleX(Number p_numX, Number p_numRadius, Number p_numAngle)Calculate the x-coordinate of a point on a ellipse.doublecircleX(Number p_numX, Number p_numRadius, Number p_numNum, Number p_numDenom)Calculate the x-coordinate of a point on a ellipse.intcircleXInt(Number p_numX, Number p_numRadius, Number p_numAngle)Calculate the x-coordinate of a point on a ellipse.intcircleXInt(Number p_numX, Number p_numRadius, Number p_numNum, Number p_numDenom)Calculate the x-coordinate of a point on a ellipse.doublecircleY(Number p_numY, Number p_numRadius, Number p_numAngle)Calculate the y-coordinate of a point on a ellipse.doublecircleY(Number p_numY, Number p_numRadius, Number p_numNum, Number p_numDenom)Calculate the y-coordinate of a point on a ellipse.intcircleYInt(Number p_numY, Number p_numRadius, Number p_numAngle)Calculate the y-coordinate of a point on a ellipse.intcircleYInt(Number p_numY, Number p_numRadius, Number p_numNum, Number p_numDenom)Calculate the y-coordinate of a point on a ellipse.doublecos(Number p_num)Get the trigonometric cosine of the given angle.doublecosDeg(Number p_num)Get the trigonometric cosine of the given angle.doubledeg2rad(Number p_num)Convert degrees to radians.Numberdiv(Number p_numL, Number p_numR)Divides one number by another.doubleexp(Number p_numExponent)Returns Euler's number e raised to given power as adouble.doublefloor(double p_dbl)Returns the largest double value that is less than or equal to the argument and is equal to a mathematical integer.booleange(Number p_numL, Number p_numR)Determine if the first number is greater or equal as the second number.doublegetPI()Get the value of π, i.e.intgetRandomInt(int p_iMinValue, int p_iMaxValue)longgetRandomLong(long p_lMinValue, long p_lMaxValue)booleangt(Number p_numL, Number p_numR)Determine if the first number is greater than the second number.intidiv(Number p_numL, Number p_numR)Divides theintpart of first number by theintpart of the second.intimod(Number p_numL, Number p_numR)Calculates theintpart of first number modulo theintpart of the second.booleanisInfinite(double p_dbl)Check if the specified number is infinitely large in magnitude.booleanisInfinite(float p_flt)Check if the specified number is infinitely large in magnitude.booleanisNaN(double p_dbl)Check if the specified number is a Not-a-Number (NaN) value.booleanisNaN(float p_flt)Check if the specified number is a Not-a-Number (NaN) value.longldiv(Number p_numL, Number p_numR)Divides thelongpart of first number by thelongpart of the second.booleanle(Number p_numL, Number p_numR)Determine if the first number is less or equal the second number.longlmod(Number p_numL, Number p_numR)Calculates thelongpart of first number modulo thelongpart of the second.doublelog(Number p_num)Returns the natural logarithm (base e) of the given number as adouble.doublelog10(Number p_num)Returns the logarithm to base10of the given number as adouble.booleanlt(Number p_numL, Number p_numR)Determine if the first number is less than the second number.Numbermax(Number p_num1, Number p_num2)Determine the maximum of the given numbers.Numbermin(Number p_num1, Number p_num2)Determine the minimum of the given numbers.Numbermult(Number p_numL, Number p_numR)Multiplies two numbers.doublepow(Number p_numBase, Number p_numExponent)Returns the value of the first argument raised to the power of the second argument as adouble.doublerad2deg(Number p_num)Convert radians to degrees.doubleratio2rad(Number p_numNum, Number p_numDenom)Convert a ratio to radians.doubleroundHalfAwayFromZero(double p_dbl)Returns the closest integer to the argument.doubleroundHalfAwayFromZero(double p_dbl, int p_iPrecision)Returns the closest scaled integer to the argument.BigDecimalroundHalfAwayFromZero(BigDecimal p_bd)Returns the closest integer to the argument.BigDecimalroundHalfAwayFromZero(BigDecimal p_bd, int p_iPrecision)Returns the closest scaled integer to the argument.introundHalfAwayFromZeroAsInt(double p_dbl)Returns the closestintto the argument.longroundHalfAwayFromZeroAsLong(double p_dbl)Returns the closestlongto the argument.doubleroundHalfEven(double p_dbl)Returns the closest integer to the argument.doubleroundHalfEven(double p_dbl, int p_iPrecision)Returns the closest integer to the argument.BigDecimalroundHalfEven(BigDecimal p_bd)Returns the closest integer to the argument.BigDecimalroundHalfEven(BigDecimal p_bd, int p_iPrecision)Returns the closest scaled integer to the argument.introundHalfEvenAsInt(double p_dbl)Returns the closest integer to the argument.longroundHalfEvenAsLong(double p_dbl)Returns the closest integer to the argument.doubleroundHalfUp(double p_dbl)Returns the closest integer to the argument.introundHalfUpAsInt(double p_dbl)Returns the closestintto the argument.longroundHalfUpAsLong(double p_dbl)Returns the closestlongto the argument.intsignum(Number p_num)Returns the signum function of the argument.doublesin(Number p_num)Get the trigonometric sine of the given angle.doublesinDeg(Number p_num)Get the trigonometric sine of the given angle.Numbersub(Number p_numL, Number p_numR)Subtract two numbers.doubletan(Number p_num)Get the trigonometric tangent of the given angle.doubletanDeg(Number p_num)Get the trigonometric tangent of the given angle.BigDecimaltoBigDecimal(Object p_value)Cast the given value to big decimal.BigDecimaltoBigDecimal(Object p_value, BigDecimal p_lngFallback)Cast the given value to big decimal.DoubletoDouble(Object p_value)Cast the given value to double.DoubletoDouble(Object p_value, Double p_dblFallback)Cast the given value to double.IValueHolder<?>toDoubleVH(Object p_value)Cast the given value to double and wrap it into a value holder.IValueHolder<?>toDoubleVH(Object p_value, Double p_dblFallback)Cast the given value to double and wrap it into a value holder.FloattoFloat(Object p_value)Cast the given value to float.FloattoFloat(Object p_value, Float p_fltFallback)Cast the given value to float.inttoInteger(Object p_value)Cast the given value to integer.IntegertoInteger(Object p_value, Integer p_intFallback)Cast the given value to integer.IValueHolder<?>toIntegerVH(Object p_value)Cast the given value to integer and wrap it into a value holder.IValueHolder<?>toIntegerVH(Object p_value, Integer p_intFallback)Cast the given value to integer and wrap it into a value holder.longtoLong(Object p_value)Cast the given value to long.LongtoLong(Object p_value, Long p_lngFallback)Cast the given value to long.IValueHolder<?>toLongVH(Object p_value)Cast the given value to long and wrap it into a value holder.IValueHolder<?>toLongVH(Object p_value, Long p_lngFallback)Cast the given value to long and wrap it into a value holder.
-
-
-
Field Detail
-
INT_MIN_VALUE
public static final int INT_MIN_VALUE
- See Also:
- Constant Field Values
-
INT_MAX_VALUE
public static final int INT_MAX_VALUE
- See Also:
- Constant Field Values
-
LONG_MIN_VALUE
public static final long LONG_MIN_VALUE
- See Also:
- Constant Field Values
-
LONG_MAX_VALUE
public static final long LONG_MAX_VALUE
- See Also:
- Constant Field Values
-
-
Method Detail
-
toInteger
public int toInteger(Object p_value)
Cast the given value to integer.Valid input types are
java.lang.Number,java.lang.Boolean, value holders, or strings (that must not contain decimal grouping symbols).- Parameters:
p_value- The value to be cast.- Returns:
- The integer value.
- Throws:
ArithmeticException- In case of a range overflow.NumberFormatException- If a given string cannot be parsed as an integer.
-
toIntegerVH
public IValueHolder<?> toIntegerVH(Object p_value)
Cast the given value to integer and wrap it into a value holder.- See Also:
toInteger(Object)
-
toInteger
public Integer toInteger(Object p_value, Integer p_intFallback)
Cast the given value to integer.- Parameters:
p_value- The integer value.p_intFallback- The fallback value ifp_valueisnull.- Returns:
- The integer value.
- See Also:
toInteger(Object)
-
toIntegerVH
public IValueHolder<?> toIntegerVH(Object p_value, Integer p_intFallback)
Cast the given value to integer and wrap it into a value holder.- See Also:
toInteger(Object, Integer)
-
toLong
public long toLong(Object p_value)
Cast the given value to long.Valid input types are
java.lang.Number,java.lang.Boolean, value holders, or strings (that must not contain decimal grouping symbols).- Parameters:
p_value- The value to be cast.- Returns:
- The long value.
- Throws:
ArithmeticException- In case of a range overflow.NumberFormatException- If a given string cannot be parsed as a long.
-
toLongVH
public IValueHolder<?> toLongVH(Object p_value)
Cast the given value to long and wrap it into a value holder.- See Also:
toLong(Object)
-
toLong
public Long toLong(Object p_value, Long p_lngFallback)
Cast the given value to long.- Parameters:
p_value- The long value.p_lngFallback- The fallback value ifp_valueisnull.- Returns:
- The long value.
- See Also:
toLong(Object)
-
toLongVH
public IValueHolder<?> toLongVH(Object p_value, Long p_lngFallback)
Cast the given value to long and wrap it into a value holder.- See Also:
toLong(Object, Long)
-
toFloat
public Float toFloat(Object p_value)
Cast the given value to float.Note: Prefer double over float where possible.
Valid input types are
java.lang.Number,java.lang.Boolean, value holders, or strings (seeFloat.valueOf(String)).- Parameters:
p_value- The value to be cast.- Returns:
- The float value.
- Throws:
ArithmeticException- In case of a range overflow.NumberFormatException- If a given string cannot be parsed as a float.
-
toFloat
public Float toFloat(Object p_value, Float p_fltFallback)
Cast the given value to float.Note: Prefer double over float where possible.
- Parameters:
p_value- The float value.p_fltFallback- The fallback value ifp_valueisnull.- Returns:
- The float value.
- See Also:
toFloat(Object)
-
toDoubleVH
public IValueHolder<?> toDoubleVH(Object p_value)
Cast the given value to double and wrap it into a value holder.- See Also:
toDouble(Object)
-
toDouble
public Double toDouble(Object p_value)
Cast the given value to double.Valid input types are
java.lang.Number,java.lang.Boolean, value holders, or strings (seeDouble.valueOf(String)).- Parameters:
p_value- The value to be cast.- Returns:
- The double value.
- Throws:
ArithmeticException- In case of a range overflow.NumberFormatException- If a given string cannot be parsed as a double.
-
toDouble
public Double toDouble(Object p_value, Double p_dblFallback)
Cast the given value to double.- Parameters:
p_value- The double value.p_dblFallback- The fallback value ifp_valueisnull.- Returns:
- The double value.
- See Also:
toDouble(Object)
-
toDoubleVH
public IValueHolder<?> toDoubleVH(Object p_value, Double p_dblFallback)
Cast the given value to double and wrap it into a value holder.- See Also:
toDouble(Object, Double)
-
toBigDecimal
public BigDecimal toBigDecimal(Object p_value)
Cast the given value to big decimal.Valid input types are
java.lang.Number,java.lang.Boolean, value holders, or strings.- Parameters:
p_value- The value to be cast.- Returns:
- The big decimal value.
- Throws:
ArithmeticException- In case of a range overflow.NumberFormatException- If a given string cannot be parsed as a big decimal.
-
toBigDecimal
public BigDecimal toBigDecimal(Object p_value, BigDecimal p_lngFallback)
Cast the given value to big decimal.- Parameters:
p_value- The big decimal value.p_lngFallback- The fallback value ifp_valueisnull.- Returns:
- The big decimal value.
- See Also:
toBigDecimal(Object)
-
abs
public int abs(int p_iX)
Returns the absolute value of an int value. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned.- Parameters:
p_iX- The argument whose absolute value is to be determined.- Returns:
- The absolute value.
-
abs
public long abs(long p_lX)
Returns the absolute value of a long value. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned.- Parameters:
p_lX- The argument whose absolute value is to be determined.- Returns:
- The absolute value.
-
abs
public float abs(float p_fltX)
Returns the absolute value of a float value. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned.- Parameters:
p_fltX- The argument whose absolute value is to be determined.- Returns:
- The absolute value.
-
abs
public double abs(double p_dblX)
Returns the absolute value of a double value. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned.- Parameters:
p_dblX- The argument whose absolute value is to be determined.- Returns:
- The absolute value.
-
signum
public int signum(Number p_num)
Returns the signum function of the argument.- Parameters:
p_num- The argument.- Returns:
- Zero if the argument is zero,
1if the argument is greater than zero,-1if the argument is less than zero. - Throws:
ArithmeticException- If the given value isNaN, or not finite.
-
ceil
public double ceil(double p_dbl)
Returns the smallest double value that is greater than or equal to the argument and is equal to a mathematical integer. Special cases:- If the argument value is already equal to a mathematical integer, then the result is the same as the argument.
- If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.
- If the argument value is less than zero but greater than -1.0, then the result is negative zero.
- Parameters:
p_dbl- The value.- Returns:
- The smallest (closest to negative infinity) floating-point value that is greater than or equal to the argument and is equal to a mathematical integer. .
-
floor
public double floor(double p_dbl)
Returns the largest double value that is less than or equal to the argument and is equal to a mathematical integer. Special cases:- If the argument value is already equal to a mathematical integer, then the result is the same as the argument.
- If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.
- Parameters:
p_dbl- The value.- Returns:
- The largest (closest to positive infinity) floating-point value that less than or equal to the argument and is equal to a mathematical integer.
-
roundHalfUp
public double roundHalfUp(double p_dbl)
Returns the closest integer to the argument. The result is rounded to an integer by adding 1/2, taking the floor of the result. In other words, the result is equal to the value of the expression:floor(p_dblX + 0.5d)
Examples:roundHalfUp(0) -> 0.0 roundHalfUp(0.5) -> 1.0 roundHalfUp(-0.5) -> 0.0 roundHalfUp(1) -> 1.0 roundHalfUp(-1) -> -1.0
- Parameters:
p_dbl- The value to be rounded.- Returns:
- The rounded value.
- Throws:
ArithmeticException- If the given value isNaN, or not finite.
-
roundHalfUpAsLong
public long roundHalfUpAsLong(double p_dbl)
Returns the closestlongto the argument. The result is rounded to an integer by adding 1/2, taking the floor of the result, and casting the result to typelong. In other words, the result is equal to the value of the expression:(long)floor(p_dblX + 0.5d)
Examples:roundHalfUp(0) -> 0 roundHalfUp(0.5) -> 1 roundHalfUp(-0.5) -> 0 roundHalfUp(1) -> 1 roundHalfUp(-1) -> -1
- Parameters:
p_dbl- The value to be rounded.- Returns:
- The rounded value.
- Throws:
ArithmeticException- If the given value isNaN, or less thanLong.MIN_VALUE, or greater thenLong.MAX_VALUE.
-
roundHalfUpAsInt
public int roundHalfUpAsInt(double p_dbl)
Returns the closestintto the argument. The result is rounded to an integer by adding 1/2, taking the floor of the result, and casting the result to typeint. In other words, the result is equal to the value of the expression:(long)floor(p_dblX + 0.5d)
Examples:roundHalfUp(0) -> 0 roundHalfUp(0.5) -> 1 roundHalfUp(-0.5) -> 0 roundHalfUp(1) -> 1 roundHalfUp(-1) -> -1
- Parameters:
p_dbl- The value to be rounded.- Returns:
- The rounded value.
- Throws:
ArithmeticException- If the given value isNaN, or not finite, or less thanInteger.MIN_VALUE, or greater thenInteger.MAX_VALUE.
-
roundHalfAwayFromZero
public double roundHalfAwayFromZero(double p_dbl)
Returns the closest integer to the argument. Negative half values are rounded to the lower value.Examples:
roundHalfAwayFromZero(0) -> 0.0 roundHalfAwayFromZero(0.5) -> 1.0 roundHalfAwayFromZero(-0.5) -> -1.0 roundHalfAwayFromZero(1) -> 1.0 roundHalfAwayFromZero(-1) -> -1.0
- Parameters:
p_dbl- The value to be rounded.- Returns:
- The rounded value.
- Throws:
ArithmeticException- If the given value isNaN, or not finite.
-
roundHalfAwayFromZeroAsLong
public long roundHalfAwayFromZeroAsLong(double p_dbl)
Returns the closestlongto the argument. Negative half values are rounded to the lower value.Examples:
roundHalfAwayFromZero(0) -> 0 roundHalfAwayFromZero(0.5) -> 1 roundHalfAwayFromZero(-0.5) -> -1 roundHalfAwayFromZero(1) -> 1 roundHalfAwayFromZero(-1) -> -1
- Parameters:
p_dbl- The value to be rounded.- Returns:
- The rounded value.
- Throws:
ArithmeticException- If the given value isNaN, or not finite, or less thanLong.MIN_VALUE, or greater thenLong.MAX_VALUE.
-
roundHalfAwayFromZeroAsInt
public int roundHalfAwayFromZeroAsInt(double p_dbl)
Returns the closestintto the argument. Negative half values are rounded to the lower value.Examples:
roundHalfAwayFromZero(0) -> 0 roundHalfAwayFromZero(0.5) -> 1 roundHalfAwayFromZero(-0.5) -> -1 roundHalfAwayFromZero(1) -> 1 roundHalfAwayFromZero(-1) -> -1
- Parameters:
p_dbl- The value to be rounded.- Returns:
- The rounded value.
- Throws:
ArithmeticException- If the given value isNaN, or not finite, or less thanInteger.MIN_VALUE, or greater thenInteger.MAX_VALUE.
-
roundHalfAwayFromZero
public double roundHalfAwayFromZero(double p_dbl, int p_iPrecision)Returns the closest scaled integer to the argument. Negative half values are rounded to the lower value.Examples:
roundHalfAwayFromZero(0.0, 2) -> 0.0 roundHalfAwayFromZero(1.0, 2) -> 1.0 roundHalfAwayFromZero(-1.0, 2) -> -1.0 roundHalfAwayFromZero(1.255, 2) -> 1.26 roundHalfAwayFromZero(-1.255, 2) -> -1.26 roundHalfAwayFromZero(123.5, -2) -> 100.0 roundHalfAwayFromZero(-123.5, -2) -> -100.0
- Parameters:
p_dbl- The value to be rounded.p_iPrecision- The precision (may be a negative value).- Returns:
- The rounded value.
- Throws:
ArithmeticException- If the given value isNaN, or not finite.
-
roundHalfAwayFromZero
public BigDecimal roundHalfAwayFromZero(BigDecimal p_bd)
Returns the closest integer to the argument. Negative half values are rounded to the lower value.Examples:
roundHalfAwayFromZero(0) -> 0.0 roundHalfAwayFromZero(0.5) -> 1.0 roundHalfAwayFromZero(-0.5) -> -1.0 roundHalfAwayFromZero(1) -> 1.0 roundHalfAwayFromZero(-1) -> -1.0
- Parameters:
p_bd- The value to be rounded.- Returns:
- The rounded value.
-
roundHalfAwayFromZero
public BigDecimal roundHalfAwayFromZero(BigDecimal p_bd, int p_iPrecision)
Returns the closest scaled integer to the argument. Negative half values are rounded to the lower value.Examples:
roundHalfAwayFromZero(0.0, 2) -> 0.0 roundHalfAwayFromZero(1.0, 2) -> 1.0 roundHalfAwayFromZero(-1.0, 2) -> -1.0 roundHalfAwayFromZero(1.255, 2) -> 1.26 roundHalfAwayFromZero(-1.255, 2) -> -1.26 roundHalfAwayFromZero(123.5, -2) -> 100.0 roundHalfAwayFromZero(-123.5, -2) -> -100.0
- Parameters:
p_bd- The value to be rounded.p_iPrecision- The precision (may be a negative value).- Returns:
- The rounded value.
-
roundHalfEven
public double roundHalfEven(double p_dbl)
Returns the closest integer to the argument. Half values are rounded to the neares even integer.Examples:
roundHalfEven(0) -> 0.0 roundHalfEven(1) -> 1.0 roundHalfEven(-1) -> -1.0 roundHalfEven(0.5) -> 0.0 roundHalfEven(-0.5) -> 0.0 roundHalfEven(1.5) -> 2.0 roundHalfEven(-1.5) -> -2.0 roundHalfEven(0.12) -> 0.0 roundHalfEven(-0.12) -> 0.0 roundHalfEven(0.62) -> 1.0 roundHalfEven(-0.62) -> -1.0
- Parameters:
p_dbl- The value to be rounded.- Returns:
- The rounded value.
- Throws:
ArithmeticException- If the given value isNaN, or not finite.
-
roundHalfEvenAsLong
public long roundHalfEvenAsLong(double p_dbl)
Returns the closest integer to the argument. Half values are rounded to the neares even integer.Examples:
roundHalfEven(0) -> 0 roundHalfEven(1) -> 1 roundHalfEven(-1) -> -1 roundHalfEven(0.5) -> 0 roundHalfEven(-0.5) -> 0 roundHalfEven(1.5) -> 2 roundHalfEven(-1.5) -> -2 roundHalfEven(0.12) -> 0 roundHalfEven(-0.12) -> 0 roundHalfEven(0.62) -> 1 roundHalfEven(-0.62) -> -1
- Parameters:
p_dbl- The value to be rounded.- Returns:
- The rounded value.
- Throws:
ArithmeticException- If the given value isNaN, or not finite, or less thanLong.MIN_VALUE, or greater thenLong.MAX_VALUE.
-
roundHalfEvenAsInt
public int roundHalfEvenAsInt(double p_dbl)
Returns the closest integer to the argument. Half values are rounded to the neares even integer.Examples:
roundHalfEven(0) -> 0 roundHalfEven(1) -> 1 roundHalfEven(-1) -> -1 roundHalfEven(0.5) -> 0 roundHalfEven(-0.5) -> 0 roundHalfEven(1.5) -> 2 roundHalfEven(-1.5) -> -2 roundHalfEven(0.12) -> 0 roundHalfEven(-0.12) -> 0 roundHalfEven(0.62) -> 1 roundHalfEven(-0.62) -> -1
- Parameters:
p_dbl- The value to be rounded.- Returns:
- The rounded value.
- Throws:
ArithmeticException- If the given value isNaN, or not finite, or less thanInteger.MIN_VALUE, or greater thenInteger.MAX_VALUE.
-
roundHalfEven
public double roundHalfEven(double p_dbl, int p_iPrecision)Returns the closest integer to the argument. Half values are rounded to the neares even integer.Examples:
roundHalfEven(0, 2) -> 0.0 roundHalfEven(1, 2) -> 1.0 roundHalfEven(-1, 2) -> -1.0 roundHalfEven(1.245, 2) -> 1.24 roundHalfEven(1.255, 2) -> 1.26 roundHalfEven(125.5, -2) -> 100.0 roundHalfEven(150, -2) -> 200.0
- Parameters:
p_dbl- The value to be rounded.p_iPrecision- The precision (may be a negative value).- Returns:
- The rounded value.
- Throws:
ArithmeticException- If the given value isNaN, or not finite.
-
roundHalfEven
public BigDecimal roundHalfEven(BigDecimal p_bd)
Returns the closest integer to the argument. Half values are rounded to the neares even integer.Examples:
roundHalfEven(0) -> 0.0 roundHalfEven(1) -> 1.0 roundHalfEven(-1) -> -1.0 roundHalfEven(0.5) -> 0.0 roundHalfEven(-0.5) -> 0.0 roundHalfEven(1.5) -> 2.0 roundHalfEven(-1.5) -> -2.0 roundHalfEven(0.12) -> 0.0 roundHalfEven(-0.12) -> 0.0 roundHalfEven(0.62) -> 1.0 roundHalfEven(-0.62) -> -1.0
- Parameters:
p_bd- The value to be rounded.- Returns:
- The rounded value.
-
roundHalfEven
public BigDecimal roundHalfEven(BigDecimal p_bd, int p_iPrecision)
Returns the closest scaled integer to the argument. Half values are rounded to the neares even scaled integer.Examples:
roundHalfEven(0, 2) -> 0.0 roundHalfEven(1, 2) -> 1.0 roundHalfEven(-1, 2) -> -1.0 roundHalfEven(1.245, 2) -> 1.24 roundHalfEven(1.255, 2) -> 1.26 roundHalfEven(125.5, -2) -> 100.0 roundHalfEven(150, -2) -> 200.0
- Parameters:
p_bd- The value to be rounded.p_iPrecision- The precision (may be a negative value).- Returns:
- The rounded value.
-
add
public Number add(Number p_numL, Number p_numR)
Adds two numbers. This method does not check for range overflows.- Parameters:
p_numL- The first addend.p_numR- The second addend.- Returns:
- The sum of the two values.
- Throws:
IllegalArgumentException- If either of the parameters isnull.
-
sub
public Number sub(Number p_numL, Number p_numR)
Subtract two numbers. This method does not check for range overflows.- Parameters:
p_numL- The minuend.p_numR- The subtrahend.- Returns:
- The difference of the two values.
- Throws:
IllegalArgumentException- If either of the parameters isnull.
-
mult
public Number mult(Number p_numL, Number p_numR)
Multiplies two numbers. This method does not check for range overflows.- Parameters:
p_numL- The first factor.p_numR- The second factor.- Returns:
- The product of the two factors.
- Throws:
IllegalArgumentException- If either of the parameters isnull.
-
div
public Number div(Number p_numL, Number p_numR)
Divides one number by another. This method does not check for range overflows.- Parameters:
p_numL- The dividend.p_numR- The divisor.- Returns:
- The quotient, or
Double.POSITIVE_INFINITYorDouble.NEGATIVE_INFINITYif the divisor is0. - Throws:
IllegalArgumentException- If either of the parameters isnull.
-
idiv
public int idiv(Number p_numL, Number p_numR)
Divides theintpart of first number by theintpart of the second.p_numA.intValue() / p_numB.intValue()This method does not check for range overflows.
- Parameters:
p_numL- The dividend.p_numR- The divisor.- Returns:
- The quotient.
- Throws:
IllegalArgumentException- If either of the parameters isnull.- Since:
- Intrexx 5.2.
-
ldiv
public long ldiv(Number p_numL, Number p_numR)
Divides thelongpart of first number by thelongpart of the second.p_numA.longValue() / p_numB.longValue()This method does not check for range overflows.
- Parameters:
p_numL- The dividend.p_numR- The divisor.- Returns:
- The quotient.
- Throws:
IllegalArgumentException- If either of the parameters isnull.- Since:
- Intrexx 5.2.
-
imod
public int imod(Number p_numL, Number p_numR)
Calculates theintpart of first number modulo theintpart of the second.p_numA.intValue() % p_numB.intValue()This method does not check for range overflows.
- Parameters:
p_numL- The dividend.p_numR- The divisor.- Returns:
- The remainder modulo
p_numB. - Throws:
IllegalArgumentException- If either of the parameters isnull.- Since:
- Intrexx 5.2.
-
lmod
public long lmod(Number p_numL, Number p_numR)
Calculates thelongpart of first number modulo thelongpart of the second.p_numA.intValue() % p_numB.intValue()This method does not check for range overflows.
- Parameters:
p_numL- The dividend.p_numR- The divisor.- Returns:
- The remainder modulo
p_numB. - Throws:
IllegalArgumentException- If either of the parameters isnull.- Since:
- Intrexx 5.2.
-
log
public double log(Number p_num)
Returns the natural logarithm (base e) of the given number as adouble.- Parameters:
p_num- The numerus.- Returns:
- The natural logarithm ln
p_num. - Throws:
IllegalArgumentException- If either of the parameters isnull.
-
log10
public double log10(Number p_num)
Returns the logarithm to base10of the given number as adouble.- Parameters:
p_num- The numerus.- Returns:
- The logarithm log10
p_num. - Throws:
IllegalArgumentException- If either of the parameters isnull.
-
exp
public double exp(Number p_numExponent)
Returns Euler's number e raised to given power as adouble.- Parameters:
p_numExponent- The exponent.- Returns:
- The value e
p_numExponent. - Throws:
IllegalArgumentException- If the given value isnull.
-
pow
public double pow(Number p_numBase, Number p_numExponent)
Returns the value of the first argument raised to the power of the second argument as adouble. This method does not check for range overflows.- Parameters:
p_numBase- The first factor.p_numExponent- The second factor.- Returns:
- The value
p_numBasep_numExponent. - Throws:
IllegalArgumentException- If either of the parameters isnull.
-
getPI
public double getPI()
Get the value of π, i.e.3.141592653589793.- Returns:
- The value of π
- Since:
- Intrexx 6.0.
-
rad2deg
public double rad2deg(Number p_num)
Convert radians to degrees.deg = 180 / π * rad
- Parameters:
p_num- The angle, in radians.- Returns:
- The degree value of the given radian value.
- Throws:
IllegalArgumentException- If the given value isnull.- Since:
- Intrexx 6.0.
-
deg2rad
public double deg2rad(Number p_num)
Convert degrees to radians.rad = π / 180 * deg
- Returns:
- The radian value of the given degree value.
- Throws:
IllegalArgumentException- If the given value isnull.- Since:
- Intrexx 6.0.
-
ratio2rad
public double ratio2rad(Number p_numNum, Number p_numDenom)
Convert a ratio to radians.rad = 2 * π * nom / denom
- Parameters:
p_numNum- The numerator, e.g. the arc length.p_numDenom- The denominator, e.g. the full circle.- Returns:
- The radian value that corresponds to the given ratio.
- Throws:
IllegalArgumentException- If one of the given values isnull, or if the denominator is0.- Since:
- Intrexx 6.0.
-
sin
public double sin(Number p_num)
Get the trigonometric sine of the given angle.- Parameters:
p_num- The angle, in radians.- Returns:
- The trigonometric sine of the given angle.
- Throws:
IllegalArgumentException- If the given value isnull.- Since:
- Intrexx 6.0.
-
sinDeg
public double sinDeg(Number p_num)
Get the trigonometric sine of the given angle.- Parameters:
p_num- The angle, in degrees.- Returns:
- The trigonometric sine of the given angle.
- Throws:
IllegalArgumentException- If the given value isnull.- Since:
- Intrexx 6.0.
-
cos
public double cos(Number p_num)
Get the trigonometric cosine of the given angle.- Parameters:
p_num- The angle, in radians.- Returns:
- The trigonometric cosine of the given angle.
- Throws:
IllegalArgumentException- If the given value isnull.- Since:
- Intrexx 6.0.
-
cosDeg
public double cosDeg(Number p_num)
Get the trigonometric cosine of the given angle.- Parameters:
p_num- The angle, in degrees.- Returns:
- The trigonometric cosine of the given angle.
- Throws:
IllegalArgumentException- If the given value isnull.- Since:
- Intrexx 6.0.
-
tan
public double tan(Number p_num)
Get the trigonometric tangent of the given angle.- Parameters:
p_num- The angle, in radians.- Returns:
- The trigonometric tangent of the given angle.
- Throws:
IllegalArgumentException- If the given value isnull.- Since:
- Intrexx 6.0.
-
tanDeg
public double tanDeg(Number p_num)
Get the trigonometric tangent of the given angle.- Parameters:
p_num- The angle, in degrees.- Returns:
- The trigonometric tangent of the given angle.
- Throws:
IllegalArgumentException- If the given value isnull.- Since:
- Intrexx 6.0.
-
circleX
public double circleX(Number p_numX, Number p_numRadius, Number p_numAngle)
Calculate the x-coordinate of a point on a ellipse.circleX(x, r, φ) := x + r * cos(φ)
- Parameters:
p_numX- An x offset.p_numRadius- The radius.p_numAngle- The angle, in radians.- Returns:
- The x-coordinate of a point on the circle.
- Throws:
IllegalArgumentException- If the given value isnull.- Since:
- Intrexx 6.0.
-
circleXInt
public int circleXInt(Number p_numX, Number p_numRadius, Number p_numAngle)
Calculate the x-coordinate of a point on a ellipse.circleX(x, r, φ) := x + r * cos(φ)
- Parameters:
p_numX- An x offset.p_numRadius- The radius.p_numAngle- The angle, in radians.- Returns:
- The x-coordinate of a point on the circle, rounded to the closest integer.
- Throws:
IllegalArgumentException- If the given value isnull.- Since:
- Intrexx 6.0.
-
circleX
public double circleX(Number p_numX, Number p_numRadius, Number p_numNum, Number p_numDenom)
Calculate the x-coordinate of a point on a ellipse.circleX(x, r, p, q) := x + r * cos(2 * π * p / q)
- Parameters:
p_numX- An x offset.p_numRadius- The radius.p_numNum- The numerator, e.g. the arc length.p_numDenom- The denominator, e.g. the full circle.- Returns:
- The x-coordinate of a point on the circle.
- Throws:
IllegalArgumentException- If one of the given values isnull, or if the denominator is0.- Since:
- Intrexx 6.0.
-
circleXInt
public int circleXInt(Number p_numX, Number p_numRadius, Number p_numNum, Number p_numDenom)
Calculate the x-coordinate of a point on a ellipse.circleX(x, r, p, q) := x + r * cos(2 * π * p / q)
- Parameters:
p_numX- An x offset.p_numRadius- The radius.p_numNum- The numerator, e.g. the arc length.p_numDenom- The denominator, e.g. the full circle.- Returns:
- The x-coordinate of a point on the circle, rounded to the closest integer.
- Throws:
IllegalArgumentException- If one of the given values isnull, or if the denominator is0.- Since:
- Intrexx 6.0.
-
circleY
public double circleY(Number p_numY, Number p_numRadius, Number p_numAngle)
Calculate the y-coordinate of a point on a ellipse.circleY(y, r, φ) := y + r * sin(φ)
- Parameters:
p_numY- An y offset.p_numRadius- The radius.p_numAngle- The angle, in radians.- Returns:
- The y-coordinate of a point on the circle.
- Throws:
IllegalArgumentException- If the given value isnull.- Since:
- Intrexx 6.0.
-
circleYInt
public int circleYInt(Number p_numY, Number p_numRadius, Number p_numAngle)
Calculate the y-coordinate of a point on a ellipse.circleY(y, r, φ) := y + r * sin(φ)
- Parameters:
p_numY- An y offset.p_numRadius- The radius.p_numAngle- The angle, in radians.- Returns:
- The y-coordinate of a point on the circle, rounded to the closest integer.
- Throws:
IllegalArgumentException- If the given value isnull.- Since:
- Intrexx 6.0.
-
circleY
public double circleY(Number p_numY, Number p_numRadius, Number p_numNum, Number p_numDenom)
Calculate the y-coordinate of a point on a ellipse.circleY(y, r, p, q) := y + r * sin(2 * π * p / q)
- Parameters:
p_numY- An y offset.p_numRadius- The radius.p_numNum- The numerator, e.g. the arc length.p_numDenom- The denominator, e.g. the full circle.- Returns:
- The y-coordinate of a point on the circle.
- Throws:
IllegalArgumentException- If one of the given values isnull, or if the denominator is0.- Since:
- Intrexx 6.0.
-
circleYInt
public int circleYInt(Number p_numY, Number p_numRadius, Number p_numNum, Number p_numDenom)
Calculate the y-coordinate of a point on a ellipse.circleY(y, r, p, q) := y + r * sin(2 * π * p / q)
- Parameters:
p_numRadius- The radius.p_numNum- The numerator, e.g. the arc length.p_numDenom- The denominator, e.g. the full circle.- Returns:
- The y-coordinate of a point on the circle, rounded to the closest integer.
- Throws:
IllegalArgumentException- If one of the given values isnull, or if the denominator is0.- Since:
- Intrexx 6.0.
-
isNaN
public boolean isNaN(float p_flt)
Check if the specified number is a Not-a-Number (NaN) value.- Parameters:
p_flt- The number to check.- Returns:
trueif the specified number is a Not-a-Number (NaN) value, orfalseotherwise.
-
isInfinite
public boolean isInfinite(float p_flt)
Check if the specified number is infinitely large in magnitude.- Parameters:
p_flt- The number to check.- Returns:
trueif the specified number is infinitely large in magnitude, orfalseotherwise.
-
isNaN
public boolean isNaN(double p_dbl)
Check if the specified number is a Not-a-Number (NaN) value.- Parameters:
p_dbl- The number to check.- Returns:
trueif the specified number is a Not-a-Number (NaN) value, orfalseotherwise.
-
isInfinite
public boolean isInfinite(double p_dbl)
Check if the specified number is infinitely large in magnitude.- Parameters:
p_dbl- The number to check.- Returns:
trueif the specified number is infinitely large in magnitude, orfalseotherwise.
-
min
public Number min(Number p_num1, Number p_num2)
Determine the minimum of the given numbers.- Parameters:
p_num1- The first number.p_num2- The second number.- Returns:
- The minimum of the two given numbers.
-
max
public Number max(Number p_num1, Number p_num2)
Determine the maximum of the given numbers.- Parameters:
p_num1- The first number.p_num2- The second number.- Returns:
- The maximum of the two given numbers.
-
gt
public boolean gt(Number p_numL, Number p_numR)
Determine if the first number is greater than the second number.- Parameters:
p_numL- The first number.p_numR- The second number.- Returns:
trueif the first number is greater than the second number, orfalseotherwise.
-
ge
public boolean ge(Number p_numL, Number p_numR)
Determine if the first number is greater or equal as the second number.- Parameters:
p_numL- The first number.p_numR- The second number.- Returns:
trueif the first number is greater or equal as the second number, orfalseotherwise.
-
lt
public boolean lt(Number p_numL, Number p_numR)
Determine if the first number is less than the second number.- Parameters:
p_numL- The first number.p_numR- The second number.- Returns:
trueif the first number is less than the second number, orfalseotherwise.
-
le
public boolean le(Number p_numL, Number p_numR)
Determine if the first number is less or equal the second number.- Parameters:
p_numL- The first number.p_numR- The second number.- Returns:
trueif the first number is less or equal the second number, orfalseotherwise.
-
getRandomInt
public int getRandomInt(int p_iMinValue, int p_iMaxValue)- Parameters:
p_iMinValue- The inclusive minimum value.p_iMaxValue- The exclusive maximum value.- Returns:
- An integer random number
rfrom the rangep_iMinValue <= r < p_iMaxValue. - Throws:
IllegalArgumentException- - Ifp_iMaxValue < p_iMinValue.
-
getRandomLong
public long getRandomLong(long p_lMinValue, long p_lMaxValue)- Parameters:
p_lMinValue- The inclusive minimum value.p_lMaxValue- The exclusive maximum value.- Returns:
- An integer random number
rfrom the rangep_lMinValue <= r < p_lMaxValue. - Throws:
IllegalArgumentException- - Ifp_lMaxValue < p_lMinValue.
-
-