|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.numericalmethod.suanshu.number.NumberUtils
public class NumberUtils
This class collects the utility functions to manipulate data of type Number.
These functions are static and stateless.
| Nested Class Summary | |
|---|---|
static interface |
NumberUtils.Comparable<T extends java.lang.Number>
We need a precision parameter to determine whether two numbers are close enough to be treated as equal. |
| Method Summary | |
|---|---|
static int |
compare(java.lang.Number num1,
java.lang.Number num2,
double epsilon)
Compare two Numbers. |
static boolean |
equal(java.lang.Number num1,
java.lang.Number num2,
double epsilon)
Check the equality of two Numbers, up to a precision. |
static boolean |
isReal(java.lang.Number number)
Check if a Number is a real number. |
static java.lang.Number |
parse(java.lang.String str)
Construct a Number from a String. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static boolean equal(java.lang.Number num1,
java.lang.Number num2,
double epsilon)
Numbers, up to a precision.
This method compares two numbers up to a precision.
The input type must subclass Number and implements NumberUtils.Comparable.
num1 - a numbernum2 - a numberepsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
true if their double values are equal as defined by DoubleUtils.equal(double, double, double),
or by the Object's Object.equals(java.lang.Object);
false otherwise
public static int compare(java.lang.Number num1,
java.lang.Number num2,
double epsilon)
The two inputs can be different subclasses of Number.
Complex.
num1 - a Numbernum2 - a Numberepsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0; e.g., 1e-9
d1 is close enough to d2, 1 if d1 > d2, -1 if d1 < d2public static boolean isReal(java.lang.Number number)
Number is a real number.
Specifically, we check whether doubleValue() can be called meaningfully.
TODO: this function needs to be extended or modified when a new Number subclass is implemented.
number - a number
true iff the number is real, i.e., in Rnpublic static java.lang.Number parse(java.lang.String str)
E.g.,
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"
- 1.23+4.56i + 1.23+4.56i
str - a number in String format
Number such as Double, Complex
|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||