Interface NumberSystem

  • All Known Implementing Classes:
    DefaultNumberSystem

    public interface NumberSystem
    Provides arithmetic Number operations on an implementation specific set of Number types.

    Let S be the set of possible Number values within the (given) set of Number types.
    Then S is closed under the collection of NumberSystem's methods.

    Implementation Note:
    Given S the set of possible Number values within implementation specific set of (supported) Number types:
    - implemented methods must support any Number arguments from S
    - implemented methods must also have their Number results to be in S
    Since:
    2.1, November 21, 2020
    Author:
    Andi Huber, Werner Keil
    See Also:
    Closure (wikipedia)
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static class  NumberSystem.DivisionResult
      Immutable value type, holder of 2 numbers.
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      Number abs​(Number number)
      Returns the absolute of given number as a Number that best represents the arithmetic result within the set of number types this NumberSystem supports.
      Number add​(Number x, Number y)
      Returns the sum of given x and y as a Number that best represents the arithmetic result within the set of number types this NumberSystem supports.
      int compare​(Number x, Number y)
      Compares two Number values numerically.
      Number divide​(Number x, Number y)
      Returns the division of given x and y as a Number that best represents the arithmetic result within the set of number types this NumberSystem supports.
      Number[] divideAndRemainder​(Number x, Number y, boolean roundRemainderTowardsZero)
      Returns a two-element Number array containing {x / y, x % y}
      default boolean equals​(Number x, Number y)  
      Number exp​(Number number)
      Returns Euler's Constant to the power of of given number as a Number that best represents the arithmetic result within the set of number types this NumberSystem supports.
      boolean isInteger​(Number number)
      Checks whether given number has fractional parts or not.
      boolean isLessThanOne​(Number number)  
      boolean isOne​(Number number)  
      boolean isZero​(Number number)  
      Number log​(Number number)
      Returns the natural logarithm of given number as a Number that best represents the arithmetic result within the set of number types this NumberSystem supports.
      Number multiply​(Number x, Number y)
      Returns the product of given x and y as a Number that best represents the arithmetic result within the set of number types this NumberSystem supports.
      Number narrow​(Number number)
      'Narrows' given number as a Number that best represents the numeric value within the set of number types this NumberSystem supports.
      Number negate​(Number number)
      Returns the negation of given number as a Number that best represents the arithmetic result within the set of number types this NumberSystem supports.
      Number power​(Number number, int exponent)
      Returns given number to the power of exponent as a Number that best represents the arithmetic result within the set of number types this NumberSystem supports.
      Number reciprocal​(Number number)
      Returns the reciprocal of given number as a Number that best represents the arithmetic result within the set of number types this NumberSystem supports.
      int signum​(Number number)
      Returns the signum function of given number.
      Number subtract​(Number x, Number y)
      Returns the difference of given x and y as a Number that best represents the arithmetic result within the set of number types this NumberSystem supports.
    • Method Detail

      • add

        Number add​(Number x,
                   Number y)
        Returns the sum of given x and y as a Number that best represents the arithmetic result within the set of number types this NumberSystem supports.
        Parameters:
        x -
        y -
        Returns:
        x + y
      • subtract

        Number subtract​(Number x,
                        Number y)
        Returns the difference of given x and y as a Number that best represents the arithmetic result within the set of number types this NumberSystem supports.
        Parameters:
        x -
        y -
        Returns:
        x - y
      • multiply

        Number multiply​(Number x,
                        Number y)
        Returns the product of given x and y as a Number that best represents the arithmetic result within the set of number types this NumberSystem supports.
        Parameters:
        x -
        y -
        Returns:
        x * y
      • divide

        Number divide​(Number x,
                      Number y)
        Returns the division of given x and y as a Number that best represents the arithmetic result within the set of number types this NumberSystem supports.
        Parameters:
        x -
        y -
        Returns:
        x / y
      • divideAndRemainder

        Number[] divideAndRemainder​(Number x,
                                    Number y,
                                    boolean roundRemainderTowardsZero)
        Returns a two-element Number array containing {x / y, x % y}
        Parameters:
        x -
        y -
        roundRemainderTowardsZero - - whether the division remainder should be rounded towards zero
        Returns:
      • power

        Number power​(Number number,
                     int exponent)
        Returns given number to the power of exponent as a Number that best represents the arithmetic result within the set of number types this NumberSystem supports.
        Parameters:
        number -
        exponent - - an integer
        Returns:
        number^exponent
        Throws:
        ArithmeticException - if number and exponent are ZERO
      • reciprocal

        Number reciprocal​(Number number)
        Returns the reciprocal of given number as a Number that best represents the arithmetic result within the set of number types this NumberSystem supports.
        Parameters:
        number -
        Returns:
        number^-1
      • negate

        Number negate​(Number number)
        Returns the negation of given number as a Number that best represents the arithmetic result within the set of number types this NumberSystem supports.
        Parameters:
        number -
        Returns:
        -number
      • signum

        int signum​(Number number)
        Returns the signum function of given number.
        Parameters:
        number -
        Returns:
        signum(number)
      • abs

        Number abs​(Number number)
        Returns the absolute of given number as a Number that best represents the arithmetic result within the set of number types this NumberSystem supports.
        Parameters:
        number -
        Returns:
        abs(number)
      • exp

        Number exp​(Number number)
        Returns Euler's Constant to the power of of given number as a Number that best represents the arithmetic result within the set of number types this NumberSystem supports.
        Parameters:
        number -
        Returns:
        e^number, with e Euler's Constant)
      • log

        Number log​(Number number)
        Returns the natural logarithm of given number as a Number that best represents the arithmetic result within the set of number types this NumberSystem supports.
        Parameters:
        number -
        Returns:
        natural logarithm of number
      • narrow

        Number narrow​(Number number)
        'Narrows' given number as a Number that best represents the numeric value within the set of number types this NumberSystem supports.

        eg. A BigInteger that is within range of Java's Long type can be narrowed to Long w/o loss of precision.

        Parameters:
        number -
        Returns:
        'best' representation of number w/o loss of precision
      • compare

        int compare​(Number x,
                    Number y)
        Compares two Number values numerically.
        Parameters:
        x -
        y -
        Returns:
        the value 0 if x == y; a value less than 0 if x < y; and a value greater than 0 if x > y
      • isInteger

        boolean isInteger​(Number number)
        Checks whether given number has fractional parts or not.
        Parameters:
        number -
        Returns:
        whether number represents a whole number