Package org.moeaframework.util.tree
Class NumberArithmetic
java.lang.Object
org.moeaframework.util.tree.NumberArithmetic
Provides many arithmetic and trigonometric functions that operate on
Numbers, performing any necessary
implicit casting. An integer number remains an integer unless the specific function requires floating-point values.
These methods favor Long and Double representations for integer and floating-point values,
respectively.
The arithmetic functions provided herein support optional function protection, which is enabled by default.
Function protection prevents values like Inf and NaN from appearing due to invalid inputs. For
example, this protects against division-by-zero. To disable function protection, set the property
org.moeaframework.util.tree.protected_functions = false in the file
"moeaframework.properties". Inf and NaN values can still occur with function
protection enabled, so outputs should still be validated.
-
Method Summary
Modifier and TypeMethodDescriptionstatic NumberReturns the absolute value of the number.static NumberReturns the arc cosine of the number.static NumberReturns the hyperbolic arc cosine of the number.static NumberReturns the value of adding the two numbersstatic NumberReturns the arc sine of the number.static NumberReturns the hyperbolic arc sine of the number.static NumberReturns the arc tangent of the number.static NumberReturns the hyperbolic arc tangent of the number.static NumberReturns the smallest integer value greater than or equal to the given number.static NumberReturns the trigonometric cosine of the number.static NumberReturns the hyperbolic cosine of the number.static NumberReturns the value of dividing the first number by the second.static booleanReturnstrueif the two numbers are equal;falseotherwise.static NumberReturns the value from taking Euler's number e to the power of the given number.static NumberReturns the largest integer value less than or equal to the given number.static booleangreaterThan(Number a, Number b) Returnstrueif the first number is greater than the second;falseotherwise.static booleangreaterThanOrEqual(Number a, Number b) Returnstrueif the first number is greater than or equal to the second;falseotherwise.static booleanReturnstrueif the number is a floating-point value;falseotherwise.static booleanReturnstrueif the first number is less than the second;falseotherwise.static booleanlessThanOrEqual(Number a, Number b) Returnstrueif the first number is less than or equal to the second;falseotherwise.static NumberReturns the natural logarithm of the number.static NumberReturns the base-10 logarithm of the number.static NumberReturns the maximum value of two numbers.static NumberReturns the minimum value of two numbers.static NumberReturns the remainder from dividing the first number by the second.static NumberReturns the value of multiplying the two numbers.static NumberReturns the value of the first number to the power of the second.static NumberReturns the value of the number rounded to the nearest integer.static NumberReturns the sign of the number.static NumberReturns the trigonometric sine of the number.static NumberReturns the hyperbolic sine of the number.static NumberReturns the square root of the number.static NumberReturns the value of subtracting the first from the second number.static NumberReturns the trigonometric tangent of the number.static NumberReturns the hyperbolic tangent of the number.
-
Method Details
-
equals
Returnstrueif the two numbers are equal;falseotherwise.- Parameters:
a- the first numberb- the second number- Returns:
trueif the two numbers are equal;falseotherwise
-
lessThan
Returnstrueif the first number is less than the second;falseotherwise.- Parameters:
a- the first numberb- the second number- Returns:
trueif the first number is less than the second;falseotherwise
-
lessThanOrEqual
Returnstrueif the first number is less than or equal to the second;falseotherwise.- Parameters:
a- the first numberb- the second number- Returns:
trueif the first number is less than or equal to the second;falseotherwise
-
greaterThan
Returnstrueif the first number is greater than the second;falseotherwise.- Parameters:
a- the first numberb- the second number- Returns:
trueif the first number is greater than the second;falseotherwise
-
greaterThanOrEqual
Returnstrueif the first number is greater than or equal to the second;falseotherwise.- Parameters:
a- the first numberb- the second number- Returns:
trueif the first number is greater than or equal to the second;falseotherwise
-
add
Returns the value of adding the two numbers- Parameters:
a- the first numberb- the second number- Returns:
- the value of adding the two numbers
-
sqrt
Returns the square root of the number. If the number is less than zero and function protection is enabled, this functions the square root of the absolute value of the number.- Parameters:
a- the number- Returns:
- the square root of the number
- See Also:
-
pow
Returns the value of the first number to the power of the second.- Parameters:
a- the first numberb- the second number- Returns:
- the value of the first number to the power of the second
- See Also:
-
sub
Returns the value of subtracting the first from the second number.- Parameters:
a- the first numberb- the second number- Returns:
- the value of subtracting the first from the second number
-
mul
Returns the value of multiplying the two numbers.- Parameters:
a- the first numberb- the second number- Returns:
- the value of multiplying the two numbers
-
div
Returns the value of dividing the first number by the second. If the second argument is0and function protection is enabled, this function returns1regardless of the first argument's value.- Parameters:
a- the first numberb- the second number- Returns:
- the value of dividing the first number by the second
-
mod
Returns the remainder from dividing the first number by the second. If the second argument is0and function protection is enabled, this function returns0regardless of the first argument's value.- Parameters:
a- the first numberb- the second number- Returns:
- the remainder from dividing the first number by the second
-
floor
Returns the largest integer value less than or equal to the given number.- Parameters:
a- the number- Returns:
- the largest integer value less than or equal to the given number
- See Also:
-
ceil
Returns the smallest integer value greater than or equal to the given number.- Parameters:
a- the number- Returns:
- the smallest integer value greater than or equal to the given number
- See Also:
-
round
Returns the value of the number rounded to the nearest integer.- Parameters:
a- the number- Returns:
- the value of the number rounded to the nearest integer
- See Also:
-
abs
Returns the absolute value of the number.- Parameters:
a- the number- Returns:
- the absolute value of the number
- See Also:
-
log
Returns the natural logarithm of the number. If the numbers is negative and function protection is enabled, then this function returns the natural logarithm of the absolute value of the number. If the number is near zero and function protection is enabled, this function returns0.0.- Parameters:
a- the number- Returns:
- the natural logarithm of the number
- See Also:
-
log10
Returns the base-10 logarithm of the number. If the numbers is negative and function protection is enabled, then this function returns the base-10 logarithm of the absolute value of the number. If the number is near zero and function protection is enabled, this function returns0.0.- Parameters:
a- the number- Returns:
- the base-10 logarithm of the number
- See Also:
-
exp
Returns the value from taking Euler's number e to the power of the given number.- Parameters:
a- the number- Returns:
- the value from taking Euler's number e to the power of the given number
- See Also:
-
sin
Returns the trigonometric sine of the number.- Parameters:
a- the number- Returns:
- the trigonometric sine of the number
- See Also:
-
cos
Returns the trigonometric cosine of the number.- Parameters:
a- the number- Returns:
- the trigonometric cosine of the number
- See Also:
-
tan
Returns the trigonometric tangent of the number.- Parameters:
a- the number- Returns:
- the trigonometric tangent of the number
- See Also:
-
asin
Returns the arc sine of the number.- Parameters:
a- the number- Returns:
- the arc sine of the number
- See Also:
-
acos
Returns the arc cosine of the number.- Parameters:
a- the number- Returns:
- the arc cosine of the number
- See Also:
-
atan
Returns the arc tangent of the number.- Parameters:
a- the number- Returns:
- the arc tangent of the number
- See Also:
-
sinh
Returns the hyperbolic sine of the number.- Parameters:
a- the number- Returns:
- the hyperbolic sine of the number
- See Also:
-
cosh
Returns the hyperbolic cosine of the number.- Parameters:
a- the number- Returns:
- the hyperbolic cosine of the number
- See Also:
-
tanh
Returns the hyperbolic tangent of the number.- Parameters:
a- the number- Returns:
- the hyperbolic tangent of the number
- See Also:
-
asinh
Returns the hyperbolic arc sine of the number.- Parameters:
a- the number- Returns:
- the hyperbolic arc sine of the number
- See Also:
-
FastMath.asinh(double)
-
acosh
Returns the hyperbolic arc cosine of the number.- Parameters:
a- the number- Returns:
- the hyperbolic arc cosine of the number
- See Also:
-
FastMath.acosh(double)
-
atanh
Returns the hyperbolic arc tangent of the number.- Parameters:
a- the number- Returns:
- the hyperbolic arc tangent of the number
- See Also:
-
FastMath.atanh(double)
-
max
Returns the maximum value of two numbers.- Parameters:
a- the first numberb- the second number- Returns:
- the maximum value of two numbers
- See Also:
-
min
Returns the minimum value of two numbers.- Parameters:
a- the first numberb- the second number- Returns:
- the minimum value of two numbers
- See Also:
-
sign
Returns the sign of the number.- Parameters:
a- the number- Returns:
- the sign of the number
- See Also:
-
isFloatingPoint
Returnstrueif the number is a floating-point value;falseotherwise.- Parameters:
a- the number- Returns:
trueif the number is a floating-point value;falseotherwise
-