2017-07-25 13:58:09 -07:00
|
|
|
package org.nwapw.abacus.number;
|
|
|
|
|
2017-07-25 22:47:48 -07:00
|
|
|
/**
|
|
|
|
* An interface used to represent a number.
|
|
|
|
*/
|
2017-07-25 13:58:09 -07:00
|
|
|
public interface NumberInterface {
|
|
|
|
|
2017-07-25 22:47:48 -07:00
|
|
|
/**
|
2017-07-28 20:04:13 -07:00
|
|
|
* The maximum precision to which this number operates.
|
2017-07-25 22:47:48 -07:00
|
|
|
* @return the precision.
|
|
|
|
*/
|
2017-07-28 20:04:13 -07:00
|
|
|
int getMaxPrecision();
|
2017-07-25 22:47:48 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Multiplies this number by another, returning
|
|
|
|
* a new number instance.
|
|
|
|
* @param multiplier the multiplier
|
|
|
|
* @return the result of the multiplication.
|
|
|
|
*/
|
2017-07-25 13:58:09 -07:00
|
|
|
NumberInterface multiply(NumberInterface multiplier);
|
2017-07-25 22:47:48 -07:00
|
|
|
/**
|
|
|
|
* Divides this number by another, returning
|
|
|
|
* a new number instance.
|
|
|
|
* @param divisor the divisor
|
|
|
|
* @return the result of the division.
|
|
|
|
*/
|
2017-07-25 13:58:09 -07:00
|
|
|
NumberInterface divide(NumberInterface divisor);
|
2017-07-25 22:47:48 -07:00
|
|
|
/**
|
|
|
|
* Adds this number to another, returning
|
|
|
|
* a new number instance.
|
|
|
|
* @param summand the summand
|
|
|
|
* @return the result of the summation.
|
|
|
|
*/
|
2017-07-25 13:58:09 -07:00
|
|
|
NumberInterface add(NumberInterface summand);
|
2017-07-25 22:47:48 -07:00
|
|
|
/**
|
|
|
|
* Subtracts another number from this number,
|
|
|
|
* a new number instance.
|
|
|
|
* @param subtrahend the subtrahend.
|
|
|
|
* @return the result of the subtraction.
|
|
|
|
*/
|
2017-07-25 13:58:09 -07:00
|
|
|
NumberInterface subtract(NumberInterface subtrahend);
|
2017-07-25 22:47:48 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a new instance of this number with
|
|
|
|
* the sign flipped.
|
|
|
|
* @return the new instance.
|
|
|
|
*/
|
2017-07-25 13:58:09 -07:00
|
|
|
NumberInterface negate();
|
2017-07-25 22:47:48 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Raises this number to an integer power.
|
2017-07-26 19:28:57 -07:00
|
|
|
* @param exponent the exponent to which to take the number.
|
|
|
|
* @return the resulting value.
|
2017-07-25 22:47:48 -07:00
|
|
|
*/
|
2017-07-25 13:58:09 -07:00
|
|
|
NumberInterface intPow(int exponent);
|
2017-07-25 22:47:48 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Compares this number to another.
|
|
|
|
* @param number the number to compare to.
|
|
|
|
* @return same as Integer.compare();
|
|
|
|
*/
|
2017-07-25 13:58:09 -07:00
|
|
|
int compareTo(NumberInterface number);
|
2017-07-25 22:47:48 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Same as Math.signum().
|
|
|
|
* @return 1 if this number is positive, -1 if this number is negative, 0 if this number is 0.
|
|
|
|
*/
|
2017-07-25 13:58:09 -07:00
|
|
|
int signum();
|
|
|
|
|
2017-07-25 22:47:48 -07:00
|
|
|
/**
|
|
|
|
* Promotes this class to another number class.
|
|
|
|
* @param toClass the class to promote to.
|
|
|
|
* @return the resulting new instance.
|
|
|
|
*/
|
2017-07-25 13:58:09 -07:00
|
|
|
NumberInterface promoteTo(Class<? extends NumberInterface> toClass);
|
|
|
|
|
|
|
|
}
|