|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.northwestern.at.utils.math.NumberOps
public class NumberOps
Perform arithmetic on java.lang.Number objects.
Field Summary | |
---|---|
protected static java.lang.Number |
intZero
Integer zero as a Number. |
Constructor Summary | |
---|---|
NumberOps()
|
Method Summary | |
---|---|
static java.lang.Number |
add(java.lang.Number number1,
java.lang.Number number2)
Add two numbers. |
static java.lang.Number |
cloneNumber(java.lang.Number number)
Get copy of a Number object. |
static int |
compareNumbers(java.lang.Number number1,
java.lang.Number number2)
Compare two numbers. |
static int |
compareToZero(java.lang.Number number)
Compare a number to zero. |
static java.lang.Number |
divide(java.lang.Number number1,
java.lang.Number number2)
Divide two numbers. |
static java.lang.Number |
modulus(java.lang.Number number1,
java.lang.Number number2)
Find modulus of two numbers. |
static java.lang.Number |
multiply(java.lang.Number number1,
java.lang.Number number2)
Multiply two numbers. |
static java.lang.Number |
subtract(java.lang.Number number1,
java.lang.Number number2)
Substract two numbers. |
static java.lang.Number |
toNumber(java.lang.String s)
Convert string to Number. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final java.lang.Number intZero
Constructor Detail |
---|
public NumberOps()
Method Detail |
---|
public static int compareNumbers(java.lang.Number number1, java.lang.Number number2)
number1
- First number.number2
- Second number.
public static int compareToZero(java.lang.Number number)
number
- Number to compare to zero.
public static java.lang.Number add(java.lang.Number number1, java.lang.Number number2)
number1
- First number.number2
- Second number.
If both number1 and number2 are Integers, the result is an Integer. Any other combination of Number types results in a Double.
public static java.lang.Number subtract(java.lang.Number number1, java.lang.Number number2)
number1
- First number.number2
- Second number.
If both number1 and number2 are Integers, the result is an Integer. Any other combination of Number types results in a Double.
public static java.lang.Number multiply(java.lang.Number number1, java.lang.Number number2)
number1
- First number.number2
- Second number.
If both number1 and number2 are Integers, the result is an Integer. Any other combination of Number types results in a Double.
public static java.lang.Number divide(java.lang.Number number1, java.lang.Number number2)
number1
- First number.number2
- Second number.
If both number1 and number2 are Integers, the result is an Integer. Any other combination of Number types results in a Double. Zerodivides are passed through as NAN.
public static java.lang.Number modulus(java.lang.Number number1, java.lang.Number number2)
number1
- First number.number2
- Second number.
The numbers are converted to Longs before performing the operation. The result is a Long. This gives the expected results if the numbers are both integral.
public static java.lang.Number toNumber(java.lang.String s) throws java.lang.NumberFormatException
s
- String to convert to Number.
java.lang.NumberFormatException
- if "s" does not contain
a valid number.
If the string contains an integer, the resulting Number is an Integer. Anything other valid numeric string is converted to a Double. An invalid numeric string throws a NumberFormatException.
public static java.lang.Number cloneNumber(java.lang.Number number)
number
- The number object for which a copy is desired.
This method exists because Java does not implement a proper clone method for the Number class.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |