| Modifier and Type | Class and Description |
|---|---|
static interface |
NumberUtils.Comparable<T extends Number>
We need a precision parameter to determine whether two numbers are close enough to be treated
as equal.
|
| Modifier and Type | Method and Description |
|---|---|
static int |
compare(Number num1,
Number num2,
double epsilon)
Compare two numbers.
|
static boolean |
equal(Number num1,
Number num2,
double epsilon)
Check the equality of two
Numbers, up to a precision. |
static boolean |
isReal(Number number)
Check if a number is a real number.
|
static Number |
parse(String str)
Construct a number from a String.
|
static Number[] |
parseArray(String... strs)
|
public static boolean equal(Number num1, Number num2, double epsilon)
Numbers, up to a precision.num1 - a numbernum2 - a numberepsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0true if the numbers are close enough, false otherwisepublic static int compare(Number num1, Number num2, double epsilon)
Number.
double, they are compared as doubles; e.g., 2 vs.
new Double(3);double but the other is not, the double is cast into the same
field as the other number for comparison; e.g., 4 vs. 3 + 0i;double, the two numbers must be of the same class for comparison;
e.g., both are Complex.num1 - a numbernum2 - a numberepsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0;
e.g., 1e-9num1 is close enough to num2; 1 if num1 > num2; -1 if
num1 < num2public static boolean isReal(Number number)
Number subclass is
implemented.
number - a numbertrue if the number is real, i.e., in Rnpublic static Number parse(String str)
Note: having spaces in the real part between sign and number is illegal, e.g.,"2" "2." "3 + 5i" "1.23 - 4.56i" "-1.23 - 4.56i" "-1.23 - 4.56e-7i" "-1.23 - 4.56+e7i" "i"
TODO: this function needs to be extended or modified when a new- 1.23+4.56i + 1.23+4.56i
Number subclass is
implemented.
Copyright © 2010-2020 NM FinTech Ltd.. All Rights Reserved.