Top Description Fields Constructors Methods
tech.units.indriya.internal.function

public final Class Calculator

extends Object
Class Inheritance
Annotations
@API
status:INTERNAL
Static Imports
org.apiguardian.api.API.Status.INTERNAL

Provides arithmetic on Java Numbers utilizing a provided NumberSystem.
Authors
Andi Huber, Werner Keil
Since
2.0
Version
2.1, May 14, 2021

Field Summary

Modifier and TypeField and Description
private Number
private final NumberSystem

Constructor Summary

AccessConstructor and Description
private
Calculator(NumberSystem ns)

Returns a new instance of a Calculator initialized with the given NumberSystem.

private
Calculator()

Returns a new instance of a Calculator initialized with the default NumberSystem, as set at Calculus#currentNumberSystem()

This implementation is *not* thread-safe, hence threads should not share instances of this.

Method Summary

Modifier and TypeMethod and Description
public Calculator

Returns:

self
abs
()

Calculates the absolute value of this Calculator´s accumulator, then stores the result in the accumulator.

public Calculator

Returns:

self
add
(Number number)

Adds number to this Calculator´s accumulator, then stores the result in the accumulator.

public Calculator

Returns:

self
divide
(Number number)

Divides this Calculator´s accumulator by number, then stores the result in the accumulator.

public Calculator

Returns:

self
exp
()

Calculates Euler's constant taken to the power of this Calculator´s accumulator, then stores the result in the accumulator.

private static Calculator

Returns:

a Calculator initialized with the default NumberSystem
getInstance
()

Returns a new instance of a Calculator initialized with the default NumberSystem, as set at Calculus#currentNumberSystem()

This implementation is *not* thread-safe, hence threads should not share instances of this.

public boolean

Returns:

whether this Calculator´s accumulator is less than ONE
isLessThanOne
()

private Calculator

Returns:

self
load
(Number number)

Loads number into this Calculator´s accumulator.

public Calculator

Returns:

self
log
()

Calculates the natural logarithm of this Calculator´s accumulator, then stores the result in the accumulator.

public Calculator

Returns:

self
multiply
(Number number)

Multiplies number with this Calculator´s accumulator, then stores the result in the accumulator.

public Calculator

Returns:

self
negate
()

Calculates the additive inverse value of this Calculator´s accumulator, then stores the result in the accumulator.

public static Calculator

Returns:

default Calculator with number loaded into its accumulator
of
(Number number)

Shortcut for getDefault().load(number).

public Number

Returns:

a narrowed version of this Calculator´s accumulator
peek
()

Allows to 'peek' at this Calculator´s accumulator.

public Calculator

Returns:

self
power
(int exponent)

Takes this Calculator´s accumulator to the integer power of exponent, then stores the result in the accumulator.

public Calculator

Returns:

self
reciprocal
()

Calculates the multiplicative inverse value of this Calculator´s accumulator, then stores the result in the accumulator.

public Calculator

Returns:

self
subtract
(Number number)

Subtracts number from this Calculator´s accumulator, then stores the result in the accumulator.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

accback to summary
private Number acc
nsback to summary
private final NumberSystem ns

Constructor Detail

Calculatorback to summary
private Calculator(NumberSystem ns)

Returns a new instance of a Calculator initialized with the given NumberSystem.

Parameters
ns:NumberSystem

the NumberSystem

Calculatorback to summary
private Calculator()

Returns a new instance of a Calculator initialized with the default NumberSystem, as set at Calculus#currentNumberSystem()

This implementation is *not* thread-safe, hence threads should not share instances of this.

Method Detail

absback to summary
public Calculator abs()

Calculates the absolute value of this Calculator´s accumulator, then stores the result in the accumulator.

Returns:Calculator

self

addback to summary
public Calculator add(Number number)

Adds number to this Calculator´s accumulator, then stores the result in the accumulator.

Returns:Calculator

self

divideback to summary
public Calculator divide(Number number)

Divides this Calculator´s accumulator by number, then stores the result in the accumulator.

Returns:Calculator

self

expback to summary
public Calculator exp()

Calculates Euler's constant taken to the power of this Calculator´s accumulator, then stores the result in the accumulator.

Returns:Calculator

self

getInstanceback to summary
private static Calculator getInstance()

Returns a new instance of a Calculator initialized with the default NumberSystem, as set at Calculus#currentNumberSystem()

This implementation is *not* thread-safe, hence threads should not share instances of this.

Returns:Calculator

a Calculator initialized with the default NumberSystem

isLessThanOneback to summary
public boolean isLessThanOne()
Returns:boolean

whether this Calculator´s accumulator is less than ONE

loadback to summary
private Calculator load(Number number)

Loads number into this Calculator´s accumulator.

Returns:Calculator

self

logback to summary
public Calculator log()

Calculates the natural logarithm of this Calculator´s accumulator, then stores the result in the accumulator.

Returns:Calculator

self

multiplyback to summary
public Calculator multiply(Number number)

Multiplies number with this Calculator´s accumulator, then stores the result in the accumulator.

Returns:Calculator

self

negateback to summary
public Calculator negate()

Calculates the additive inverse value of this Calculator´s accumulator, then stores the result in the accumulator.

Returns:Calculator

self

ofback to summary
public static Calculator of(Number number)

Shortcut for getDefault().load(number). See getInstance() and load(Number)

Returns:Calculator

default Calculator with number loaded into its accumulator

peekback to summary
public Number peek()

Allows to 'peek' at this Calculator´s accumulator. The Number returned is narrowed to best represent the numerical value w/o loss of precision within the NumberSystem as configured for this Calculator instance.

Returns:Number

a narrowed version of this Calculator´s accumulator

powerback to summary
public Calculator power(int exponent)

Takes this Calculator´s accumulator to the integer power of exponent, then stores the result in the accumulator.

Returns:Calculator

self

reciprocalback to summary
public Calculator reciprocal()

Calculates the multiplicative inverse value of this Calculator´s accumulator, then stores the result in the accumulator.

Returns:Calculator

self

subtractback to summary
public Calculator subtract(Number number)

Subtracts number from this Calculator´s accumulator, then stores the result in the accumulator.

Returns:Calculator

self