edu.northwestern.at.utils.math

## Class NumberOps

- java.lang.Object
- - edu.northwestern.at.utils.math.NumberOps

-     public class NumberOps
      extends java.lang.Object

  Perform arithmetic on java.lang.Number objects.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static java.lang.Number` | `intZero` Integer zero as a Number.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `NumberOps()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `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

    - #### intZero

          protected static final java.lang.Number intZero

      Integer zero as a Number. Used for comparisons.

  - ### Constructor Detail

    - #### NumberOps

          public NumberOps()

  - ### Method Detail

    - #### compareNumbers

          public static int compareNumbers(java.lang.Number number1,
                           java.lang.Number number2)

      Compare two numbers.
      Parameters:
        `number1` - First number.
        `number2` - Second number.
      Returns:
        -1 if number1 < number2 0 if number1 == number2 1 if number1 > number2

    - #### compareToZero

          public static int compareToZero(java.lang.Number number)

      Compare a number to zero.
      Parameters:
        `number` - Number to compare to zero.
      Returns:
        -1 if number < 0 0 if number1 == 0 1 if number1 > 0

    - #### add

          public static java.lang.Number add(java.lang.Number number1,
                             java.lang.Number number2)

      Add two numbers.
      Parameters:
        `number1` - First number.
        `number2` - Second number.
      Returns:
        Sum of number1 and number2.

        If both number1 and number2 are Integers, the result is an Integer. Any other combination of Number types results in a Double.

    - #### subtract

          public static java.lang.Number subtract(java.lang.Number number1,
                                  java.lang.Number number2)

      Substract two numbers.
      Parameters:
        `number1` - First number.
        `number2` - Second number.
      Returns:
        number1 - number2 .

        If both number1 and number2 are Integers, the result is an Integer. Any other combination of Number types results in a Double.

    - #### multiply

          public static java.lang.Number multiply(java.lang.Number number1,
                                  java.lang.Number number2)

      Multiply two numbers.
      Parameters:
        `number1` - First number.
        `number2` - Second number.
      Returns:
        number1 * number2 .

        If both number1 and number2 are Integers, the result is an Integer. Any other combination of Number types results in a Double.

    - #### divide

          public static java.lang.Number divide(java.lang.Number number1,
                                java.lang.Number number2)

      Divide two numbers.
      Parameters:
        `number1` - First number.
        `number2` - Second number.
      Returns:
        number1 / number2 .

        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.

    - #### modulus

          public static java.lang.Number modulus(java.lang.Number number1,
                                 java.lang.Number number2)

      Find modulus of two numbers.
      Parameters:
        `number1` - First number.
        `number2` - Second number.
      Returns:
        number1 modulo number2 as a long.

        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.

    - #### toNumber

          public static java.lang.Number toNumber(java.lang.String s)
                                           throws java.lang.NumberFormatException

      Convert string to Number.
      Parameters:
        `s` - String to convert to Number.
      Returns:
        String converted to a Number.
      Throws:
        `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.

    - #### cloneNumber

          public static java.lang.Number cloneNumber(java.lang.Number number)

      Get copy of a Number object.
      Parameters:
        `number` - The number object for which a copy is desired.
      Returns:
        A copy of the specified Number object.

        This method exists because Java does not implement a proper clone method for the Number class.