Package tech.units.indriya.spi
Interface NumberSystem
-
- All Known Implementing Classes:
DefaultNumberSystem
public interface NumberSystem
Provides arithmeticNumberoperations on an implementation specific set ofNumbertypes.Let S be the set of possible
Numbervalues within the (given) set ofNumbertypes.
Then S is closed under the collection ofNumberSystem's methods.- 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 classNumberSystem.DivisionResultImmutable value type, holder of 2 numbers.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Numberabs(Number number)Returns the absolute of givennumberas aNumberthat best represents the arithmetic result within the set of number types this NumberSystem supports.Numberadd(Number x, Number y)Returns the sum of givenxandyas aNumberthat best represents the arithmetic result within the set of number types this NumberSystem supports.intcompare(Number x, Number y)Compares twoNumbervalues numerically.Numberdivide(Number x, Number y)Returns the division of givenxandyas aNumberthat 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 booleanequals(Number x, Number y)Numberexp(Number number)Returns Euler's Constant to the power of of givennumberas aNumberthat best represents the arithmetic result within the set of number types this NumberSystem supports.booleanisInteger(Number number)Checks whether givennumberhas fractional parts or not.booleanisLessThanOne(Number number)booleanisOne(Number number)booleanisZero(Number number)Numberlog(Number number)Returns the natural logarithm of givennumberas aNumberthat best represents the arithmetic result within the set of number types this NumberSystem supports.Numbermultiply(Number x, Number y)Returns the product of givenxandyas aNumberthat best represents the arithmetic result within the set of number types this NumberSystem supports.Numbernarrow(Number number)'Narrows' givennumberas aNumberthat best represents the numeric value within the set of number types this NumberSystem supports.Numbernegate(Number number)Returns the negation of givennumberas aNumberthat best represents the arithmetic result within the set of number types this NumberSystem supports.Numberpower(Number number, int exponent)Returns givennumberto the power ofexponentas aNumberthat best represents the arithmetic result within the set of number types this NumberSystem supports.Numberreciprocal(Number number)Returns the reciprocal of givennumberas aNumberthat best represents the arithmetic result within the set of number types this NumberSystem supports.intsignum(Number number)Returns the signum function of givennumber.Numbersubtract(Number x, Number y)Returns the difference of givenxandyas aNumberthat 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 givenxandyas aNumberthat 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 givenxandyas aNumberthat 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 givenxandyas aNumberthat 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 givenxandyas aNumberthat 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 givennumberto the power ofexponentas aNumberthat best represents the arithmetic result within the set of number types this NumberSystem supports.- Parameters:
number-exponent- - an integer- Returns:
- number^exponent
- Throws:
ArithmeticException- ifnumberandexponentare ZERO
-
reciprocal
Number reciprocal(Number number)
Returns the reciprocal of givennumberas aNumberthat 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 givennumberas aNumberthat 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 givennumber.- Parameters:
number-- Returns:
signum(number)
-
abs
Number abs(Number number)
Returns the absolute of givennumberas aNumberthat 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 givennumberas aNumberthat best represents the arithmetic result within the set of number types this NumberSystem supports.- Parameters:
number-- Returns:
e^number, witheEuler's Constant)
-
log
Number log(Number number)
Returns the natural logarithm of givennumberas aNumberthat 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' givennumberas aNumberthat best represents the numeric value within the set of number types this NumberSystem supports.eg. A BigInteger that is within range of Java's
Longtype can be narrowed to Long w/o loss of precision.- Parameters:
number-- Returns:
- 'best' representation of
numberw/o loss of precision
-
compare
int compare(Number x, Number y)
Compares twoNumbervalues numerically.- Parameters:
x-y-- Returns:
- the value
0ifx == y; a value less than0ifx < y; and a value greater than0ifx > y
-
isLessThanOne
boolean isLessThanOne(Number number)
-
isInteger
boolean isInteger(Number number)
Checks whether givennumberhas fractional parts or not.- Parameters:
number-- Returns:
- whether
numberrepresents a whole number
-
-