Class Calculator
- java.lang.Object
-
- tech.units.indriya.internal.function.Calculator
-
public class Calculator extends Object
Provides arithmetic on JavaNumbers utilizing a providedNumberSystem.- Since:
- 2.0
- Author:
- Andi Huber
-
-
Method Summary
Modifier and Type Method Description Calculatorabs()Calculates the absolute value of thisCalculator´s accumulator, then stores the result in the accumulator.Calculatoradd(Number number)Addsnumberto thisCalculator´s accumulator, then stores the result in the accumulator.Calculatordivide(Number number)Divides thisCalculator´s accumulator bynumber, then stores the result in the accumulator.Calculatorexp()Calculates Euler's constant taken to the power of thisCalculator´s accumulator, then stores the result in the accumulator.protected static CalculatorgetInstance()Returns a new instance of aCalculatorinitialized with the defaultNumberSystem, as set atCalculus.currentNumberSystem()booleanisLessThanOne()Calculatorload(Number number)Loadsnumberinto thisCalculator´s accumulator.Calculatorlog()Calculates the natural logarithm of thisCalculator´s accumulator, then stores the result in the accumulator.Calculatormultiply(Number number)Multipliesnumberwith thisCalculator´s accumulator, then stores the result in the accumulator.Calculatornegate()Calculates the additive inverse value of thisCalculator´s accumulator, then stores the result in the accumulator.static Calculatorof(Number number)Shortcut forgetDefault().load(number).Numberpeek()Allows to 'peek' at thisCalculator´s accumulator.Calculatorpower(int exponent)Takes thisCalculator´s accumulator to the integer power ofexponent, then stores the result in the accumulator.Calculatorreciprocal()Calculates the multiplicative inverse value of thisCalculator´s accumulator, then stores the result in the accumulator.Calculatorsubtract(Number number)Subtractsnumberfrom thisCalculator´s accumulator, then stores the result in the accumulator.
-
-
-
Method Detail
-
getInstance
protected static Calculator getInstance()
Returns a new instance of aCalculatorinitialized with the defaultNumberSystem, as set atCalculus.currentNumberSystem()This implementation is *not* thread-safe, hence threads should not share instances of this.
- Returns:
- a
Calculatorinitialized with the defaultNumberSystem
-
of
public static Calculator of(Number number)
- Parameters:
number-- Returns:
- default
Calculatorwithnumberloaded into its accumulator
-
load
public Calculator load(Number number)
Loadsnumberinto thisCalculator´s accumulator.- Parameters:
number-- Returns:
- self
-
add
public Calculator add(Number number)
Addsnumberto thisCalculator´s accumulator, then stores the result in the accumulator.- Parameters:
number-- Returns:
- self
-
subtract
public Calculator subtract(Number number)
Subtractsnumberfrom thisCalculator´s accumulator, then stores the result in the accumulator.- Parameters:
number-- Returns:
- self
-
multiply
public Calculator multiply(Number number)
Multipliesnumberwith thisCalculator´s accumulator, then stores the result in the accumulator.- Parameters:
number-- Returns:
- self
-
divide
public Calculator divide(Number number)
Divides thisCalculator´s accumulator bynumber, then stores the result in the accumulator.- Parameters:
number-- Returns:
- self
-
power
public Calculator power(int exponent)
Takes thisCalculator´s accumulator to the integer power ofexponent, then stores the result in the accumulator.- Parameters:
exponent-- Returns:
- self
-
abs
public Calculator abs()
Calculates the absolute value of thisCalculator´s accumulator, then stores the result in the accumulator.- Returns:
- self
-
negate
public Calculator negate()
Calculates the additive inverse value of thisCalculator´s accumulator, then stores the result in the accumulator.- Returns:
- self
-
reciprocal
public Calculator reciprocal()
Calculates the multiplicative inverse value of thisCalculator´s accumulator, then stores the result in the accumulator.- Returns:
- self
-
exp
public Calculator exp()
Calculates Euler's constant taken to the power of thisCalculator´s accumulator, then stores the result in the accumulator.- Returns:
- self
-
log
public Calculator log()
Calculates the natural logarithm of thisCalculator´s accumulator, then stores the result in the accumulator.- Returns:
- self
-
peek
public Number peek()
Allows to 'peek' at thisCalculator´s accumulator. TheNumberreturned is narrowed to best represent the numerical value w/o loss of precision within theNumberSystemas configured for thisCalculatorinstance.- Returns:
- a narrowed version of this
Calculator´s accumulator
-
isLessThanOne
public boolean isLessThanOne()
- Returns:
- whether this
Calculator´s accumulator is less than ONE
-
-