Package org.moeaframework.util.tree
Class NumberArithmetic
java.lang.Object
org.moeaframework.util.tree.NumberArithmetic
Provides many arithmetic and trigonometric functions that operate on
Number
s, 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 Number
Returns the absolute value of the number.static Number
Returns the arc cosine of the number.static Number
Returns the hyperbolic arc cosine of the number.static Number
Returns the value of adding the two numbersstatic Number
Returns the arc sine of the number.static Number
Returns the hyperbolic arc sine of the number.static Number
Returns the arc tangent of the number.static Number
Returns the hyperbolic arc tangent of the number.static Number
Returns the smallest integer value greater than or equal to the given number.static Number
Returns the trigonometric cosine of the number.static Number
Returns the hyperbolic cosine of the number.static Number
Returns the value of dividing the first number by the second.static boolean
Returnstrue
if the two numbers are equal;false
otherwise.static Number
Returns the value from taking Euler's number e to the power of the given number.static Number
Returns the largest integer value less than or equal to the given number.static boolean
greaterThan
(Number a, Number b) Returnstrue
if the first number is greater than the second;false
otherwise.static boolean
greaterThanOrEqual
(Number a, Number b) Returnstrue
if the first number is greater than or equal to the second;false
otherwise.static boolean
Returnstrue
if the number is a floating-point value;false
otherwise.static boolean
Returnstrue
if the first number is less than the second;false
otherwise.static boolean
lessThanOrEqual
(Number a, Number b) Returnstrue
if the first number is less than or equal to the second;false
otherwise.static Number
Returns the natural logarithm of the number.static Number
Returns the base-10 logarithm of the number.static Number
Returns the maximum value of two numbers.static Number
Returns the minimum value of two numbers.static Number
Returns the remainder from dividing the first number by the second.static Number
Returns the value of multiplying the two numbers.static Number
Returns the value of the first number to the power of the second.static Number
Returns the value of the number rounded to the nearest integer.static Number
Returns the sign of the number.static Number
Returns the trigonometric sine of the number.static Number
Returns the hyperbolic sine of the number.static Number
Returns the square root of the number.static Number
Returns the value of subtracting the first from the second number.static Number
Returns the trigonometric tangent of the number.static Number
Returns the hyperbolic tangent of the number.
-
Method Details
-
equals
Returnstrue
if the two numbers are equal;false
otherwise.- Parameters:
a
- the first numberb
- the second number- Returns:
true
if the two numbers are equal;false
otherwise
-
lessThan
Returnstrue
if the first number is less than the second;false
otherwise.- Parameters:
a
- the first numberb
- the second number- Returns:
true
if the first number is less than the second;false
otherwise
-
lessThanOrEqual
Returnstrue
if the first number is less than or equal to the second;false
otherwise.- Parameters:
a
- the first numberb
- the second number- Returns:
true
if the first number is less than or equal to the second;false
otherwise
-
greaterThan
Returnstrue
if the first number is greater than the second;false
otherwise.- Parameters:
a
- the first numberb
- the second number- Returns:
true
if the first number is greater than the second;false
otherwise
-
greaterThanOrEqual
Returnstrue
if the first number is greater than or equal to the second;false
otherwise.- Parameters:
a
- the first numberb
- the second number- Returns:
true
if the first number is greater than or equal to the second;false
otherwise
-
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 is0
and function protection is enabled, this function returns1
regardless 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 is0
and function protection is enabled, this function returns0
regardless 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
Returnstrue
if the number is a floating-point value;false
otherwise.- Parameters:
a
- the number- Returns:
true
if the number is a floating-point value;false
otherwise
-