Top Description Inners Methods
tech.units.indriya.spi

public Interface NumberSystem

Known Direct Implementers
tech.units.indriya.function.DefaultNumberSystem

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
Authors
Andi Huber, Werner Keil
Since
2.1, November 21, 2020
See Also
Closure (wikipedia)

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
NumberSystem.DivisionResult

Immutable value type, holder of 2 numbers.

Method Summary

Modifier and TypeMethod and Description
public Number

Returns:

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.

public Number

Returns:

x + y
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.

public int

Returns:

the value 0 if x == y; a value less than 0 if x < y; and a value greater than 0 if x > y
compare
(Number x, Number y)

Compares two Number values numerically.

public Number

Returns:

x / y
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.

public Number[]
divideAndRemainder(Number x, Number y, boolean
- whether the division remainder should be rounded towards zero
roundRemainderTowardsZero
)

Returns a two-element Number array containing {x / y, x % y}

public default boolean
public Number

Returns:

e^number, with e Euler's Constant)
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.

public boolean

Returns:

whether number represents a whole number
isInteger
(Number number)

Checks whether given number has fractional parts or not.

public boolean
public boolean
isOne(Number number)

public boolean
isZero(Number number)

public Number

Returns:

natural logarithm of 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.

public Number

Returns:

x * y
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.

public Number

Returns:

'best' representation of number w/o loss of precision
narrow
(Number number)

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

public Number

Returns:

-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.

public Number

Returns:

number^exponent
power
(Number number, int
- an integer
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.

public Number

Returns:

number^-1
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.

public int

Returns:

signum(number)
signum
(Number number)

Returns the signum function of given number.

public Number

Returns:

x - y
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

absback to summary
public 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.

Returns:Number

abs(number)

addback to summary
public 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.

Returns:Number

x + y

compareback to summary
public int compare(Number x, Number y)

Compares two Number values numerically.

Returns:int

the value 0 if x == y; a value less than 0 if x < y; and a value greater than 0 if x > y

divideback to summary
public 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.

Returns:Number

x / y

divideAndRemainderback to summary
public Number[] divideAndRemainder(Number x, Number y, boolean roundRemainderTowardsZero)

Returns a two-element Number array containing {x / y, x % y}

Parameters
roundRemainderTowardsZero:boolean

- whether the division remainder should be rounded towards zero

equalsback to summary
public default boolean equals(Number x, Number y)
expback to summary
public 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.

Returns:Number

e^number, with e Euler's Constant)

isIntegerback to summary
public boolean isInteger(Number number)

Checks whether given number has fractional parts or not.

Returns:boolean

whether number represents a whole number

isLessThanOneback to summary
public boolean isLessThanOne(Number number)
isOneback to summary
public boolean isOne(Number number)
isZeroback to summary
public boolean isZero(Number number)
logback to summary
public 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.

Returns:Number

natural logarithm of number

multiplyback to summary
public 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.

Returns:Number

x * y

narrowback to summary
public 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.

Returns:Number

'best' representation of number w/o loss of precision

negateback to summary
public 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.

Returns:Number

-number

powerback to summary
public 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
exponent:int

- an integer

Returns:Number

number^exponent

Exceptions
ArithmeticException:
if number and exponent are ZERO
reciprocalback to summary
public 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.

Returns:Number

number^-1

signumback to summary
public int signum(Number number)

Returns the signum function of given number.

Returns:int

signum(number)

subtractback to summary
public 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.

Returns:Number

x - y

tech.units.indriya.spi back to summary

public final Class NumberSystem.DivisionResult

extends Object
Class Inheritance

Immutable value type, holder of 2 numbers.

Field Summary

Modifier and TypeField and Description
public final Number
quotient

originating from x / y

public final Number
remainder

originating from x % y

Constructor Summary

AccessConstructor and Description
private
DivisionResult(Number quotient, Number remainder)

Method Summary

Modifier and TypeMethod and Description
public static NumberSystem.DivisionResult
of(Number quotient, Number remainder)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

quotientback to summary
public final Number quotient

originating from x / y

remainderback to summary
public final Number remainder

originating from x % y

Constructor Detail

DivisionResultback to summary
private DivisionResult(Number quotient, Number remainder)

Method Detail

ofback to summary
public static NumberSystem.DivisionResult of(Number quotient, Number remainder)