Package me.datafox.dfxengine.math.utils
Class Operations
java.lang.Object
me.datafox.dfxengine.math.utils.Operations
Various math operations for
Numerals.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Numeraladd(double augend, double addend) static Numeraladd(float augend, float addend) static Numeraladd(int augend, int addend) static Numeraladd(long augend, long addend) static BigDecNumeraladd(BigDecimal augend, BigDecimal addend) static BigIntNumeraladd(BigInteger augend, BigInteger addend) static NumeralAdds twoNumeralstogether.static Numeralcbrt(double value) static Numeralcbrt(float value) static Numeralcbrt(int value) static Numeralcbrt(long value) static Numeralcbrt(BigDecimal value) static Numeralcbrt(BigInteger value) static NumeralCalculates the cube root of aNumeral.static Numeraldivide(double dividend, double divisor) static Numeraldivide(float dividend, float divisor) static Numeraldivide(int dividend, int divisor) static Numeraldivide(long dividend, long divisor) static BigDecNumeraldivide(BigDecimal dividend, BigDecimal divisor) static BigIntNumeraldivide(BigInteger dividend, BigInteger divisor) static NumeralDivides aNumeralfrom another Numeral.static Numeralexp(double value) static Numeralexp(float value) static Numeralexp(int value) static Numeralexp(long value) static Numeralexp(BigDecimal value) static Numeralexp(BigInteger value) static NumeralCalculates the natural exponent of aNumeral.static MathContextstatic NumeralInverts aNumeral.static Numerallerp(double value, double min, double max) static Numerallerp(float value, float min, float max) static Numerallerp(int value, int min, int max) static Numerallerp(long value, long min, long max) static Numerallerp(BigDecimal value, BigDecimal min, BigDecimal max) static Numerallerp(BigInteger value, BigInteger min, BigInteger max) static NumeralLinearly interpolates aNumeralbased on a minimum and maximum numeral.static Numerallog(double value) static Numerallog(float value) static Numerallog(int value) static Numerallog(long value) static Numerallog(BigDecimal value) static Numerallog(BigInteger value) static NumeralCalculates the natural logarithm of aNumeral.static Numerallog10(double value) static Numerallog10(float value) static Numerallog10(int value) static Numerallog10(long value) static Numerallog10(BigDecimal value) static Numerallog10(BigInteger value) static NumeralCalculates the base 10 logarithm of aNumeral.static Numerallog2(double value) static Numerallog2(float value) static Numerallog2(int value) static Numerallog2(long value) static Numerallog2(BigDecimal value) static Numerallog2(BigInteger value) static NumeralCalculates the binary logarithm of aNumeral.static NumerallogN(double value, double base) static NumerallogN(float value, float base) static NumerallogN(int value, int base) static NumerallogN(long value, long base) static NumerallogN(BigDecimal value, BigDecimal base) static NumerallogN(BigInteger value, BigInteger base) static NumeralCalculates the logarithm aNumeralin the base of another Numeral.static NumeralReturns the maximum of twoNumerals, that is, the Numeral that represents a greater number.static NumeralReturns the minimum of twoNumerals, that is, the Numeral that represents a lesser number.static Numeralmultiply(double multiplicand, double multiplier) static Numeralmultiply(float multiplicand, float multiplier) static Numeralmultiply(int multiplicand, int multiplier) static Numeralmultiply(long multiplicand, long multiplier) static BigDecNumeralmultiply(BigDecimal multiplicand, BigDecimal multiplier) static BigIntNumeralmultiply(BigInteger multiplicand, BigInteger multiplier) static NumeralMultiplies twoNumeralstogether.static Numeralpower(double base, double exponent) static Numeralpower(float base, float exponent) static Numeralpower(int base, int exponent) static Numeralpower(long base, long exponent) static Numeralpower(BigDecimal base, BigDecimal exponent) static Numeralpower(BigInteger base, BigInteger exponent) static NumeralRaises aNumeralto the power of another Numeral.static Numeralroot(double value, double base) static Numeralroot(float value, float base) static Numeralroot(int value, int base) static Numeralroot(long value, long base) static Numeralroot(BigDecimal value, BigDecimal base) static Numeralroot(BigInteger value, BigInteger base) static NumeralCalculates the root of aNumeralin the base of another Numeral.static voidsetContext(MathContext context) static Numeralsqrt(double value) static Numeralsqrt(float value) static Numeralsqrt(int value) static Numeralsqrt(long value) static Numeralsqrt(BigDecimal value) static Numeralsqrt(BigInteger value) static NumeralCalculates the square root of aNumeral.static Numeralsubtract(double minuend, double subtrahend) static Numeralsubtract(float minuend, float subtrahend) static Numeralsubtract(int minuend, int subtrahend) static Numeralsubtract(long minuend, long subtrahend) static BigDecNumeralsubtract(BigDecimal minuend, BigDecimal subtrahend) static BigIntNumeralsubtract(BigInteger minuend, BigInteger subtrahend) static NumeralSubtracts aNumeralfrom another Numeral.
-
Constructor Details
-
Operations
public Operations()
-
-
Method Details
-
getContext
- Returns:
- current
MathContextforBigDecimaloperations
-
setContext
- Parameters:
context-MathContextforBigDecimaloperations
-
add
Adds twoNumeralstogether. The Numeral parameters are converted to the most significant type withNumerals.getSignificantType(NumeralType...). Additionally, the resulting Numeral will be converted to a higher type if the addition would result in an overflow or underflow.- Parameters:
augend-Numeralto be addedaddend-Numeralto be added- Returns:
- result of the addition
- Throws:
NullPointerException- if any of theNumeralsreturnnullforNumeral.getType()IllegalArgumentException- if any of theNumeralsdo not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
subtract
Subtracts aNumeralfrom another Numeral. The Numeral parameters are converted to the most significant type withNumerals.getSignificantType(NumeralType...). Additionally, the resulting Numeral will be converted to a higher type if the subtraction would result in an overflow or underflow.- Parameters:
minuend-Numeralto be subtracted fromsubtrahend-Numeralto be subtracted- Returns:
- result of the subtraction
- Throws:
NullPointerException- if any of theNumeralsreturnnullforNumeral.getType()IllegalArgumentException- if any of theNumeralsdo not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
multiply
Multiplies twoNumeralstogether. The Numeral parameters are converted to the most significant type withNumerals.getSignificantType(NumeralType...). Additionally, the resulting Numeral will be converted to a higher type if the multiplication would result in an overflow or underflow.- Parameters:
multiplicand-Numeralto be multipliedmultiplier-Numeralto be multiplied- Returns:
- result of the multiplication
- Throws:
NullPointerException- if any of theNumeralsreturnnullforNumeral.getType()IllegalArgumentException- if any of theNumeralsdo not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
divide
Divides aNumeralfrom another Numeral. The Numeral parameters are converted to the most significant type withNumerals.getSignificantType(NumeralType...). Additionally, the resulting Numeral will be converted to a higher type if the division would result in an overflow or underflow.- Parameters:
dividend-Numeralto be divideddivisor-Numeralto be divided with- Returns:
- result of the division
- Throws:
ArithmeticException- if the divisor is zeroNullPointerException- if any of theNumeralsreturnnullforNumeral.getType()IllegalArgumentException- if any of theNumeralsdo not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
inverse
Inverts aNumeral. This is equivalent todivide(1, numeral). The resulting Numeral will be converted to a higher type if the division would result in an overflow or underflow.- Parameters:
numeral-Numeralto be inverted- Returns:
- result of the inversion
- Throws:
ArithmeticException- if the divisor is zeroNullPointerException- if theNumeralreturnsnullforNumeral.getType()IllegalArgumentException- if theNumeraldoes not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
power
Raises aNumeralto the power of another Numeral. The Numeral parameters are converted to the most significant type withNumerals.getSignificantType(NumeralType...). Additionally, the resulting Numeral will be converted to a higher type if the exponentiation would result in an overflow or underflow.- Parameters:
base-Numeralto be exponentiatedexponent- exponent- Returns:
- result of the exponentiation
- Throws:
NullPointerException- if any of theNumeralsreturnnullforNumeral.getType()IllegalArgumentException- if any of theNumeralsdo not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
exp
Calculates the natural exponent of aNumeral. The resulting Numeral will be converted to a higher type if the exponentiation would result in an overflow or underflow.- Parameters:
numeral-Numeralto be calculated- Returns:
- natural exponent of the specified
Numeral - Throws:
NullPointerException- if theNumeralreturnsnullforNumeral.getType()IllegalArgumentException- if theNumeraldoes not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
sqrt
Calculates the square root of aNumeral.- Parameters:
numeral-Numeralto be calculated- Returns:
- square root of the specified
Numeral - Throws:
ArithmeticException- if theNumeralis negativeNullPointerException- if theNumeralreturnsnullforNumeral.getType()IllegalArgumentException- if theNumeraldoes not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
cbrt
Calculates the cube root of aNumeral.- Parameters:
numeral-Numeralto be calculated- Returns:
- cube root of the specified
Numeral - Throws:
NullPointerException- if theNumeralreturnsnullforNumeral.getType()IllegalArgumentException- if theNumeraldoes not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
root
Calculates the root of aNumeralin the base of another Numeral. The Numeral parameters are converted to the most significant type withNumerals.getSignificantType(NumeralType...). Additionally, the resulting Numeral will be converted to a higher type if the operation would result in an overflow or underflow.- Parameters:
numeral-Numeralto be calculatedbase- base of the root- Returns:
- result of the operation
- Throws:
ArithmeticException- if theNumeralis negative or if the root is zeroNullPointerException- if any of theNumeralsreturnnullforNumeral.getType()IllegalArgumentException- if any of theNumeralsdo not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
log
Calculates the natural logarithm of aNumeral.- Parameters:
numeral-Numeralto be calculated- Returns:
- natural logarithm of the specified
Numeral - Throws:
ArithmeticException- if theNumeralis zero or negativeNullPointerException- if theNumeralreturnsnullforNumeral.getType()IllegalArgumentException- if theNumeraldoes not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
log2
Calculates the binary logarithm of aNumeral.- Parameters:
numeral-Numeralto be calculated- Returns:
- binary logarithm of the specified
Numeral - Throws:
ArithmeticException- if theNumeralis zero or negativeNullPointerException- if theNumeralreturnsnullforNumeral.getType()IllegalArgumentException- if theNumeraldoes not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
log10
Calculates the base 10 logarithm of aNumeral.- Parameters:
numeral-Numeralto be calculated- Returns:
- base 10 logarithm of the specified
Numeral - Throws:
ArithmeticException- if theNumeralis zero or negativeNullPointerException- if theNumeralreturnsnullforNumeral.getType()IllegalArgumentException- if theNumeraldoes not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
logN
Calculates the logarithm aNumeralin the base of another Numeral. The Numeral parameters are converted to the most significant type withNumerals.getSignificantType(NumeralType...). Additionally, the resulting Numeral will be converted to a higher type if the logarithm would result in an overflow or underflow.- Parameters:
numeral-Numeralto be calculatedbase- base of the logarithm- Returns:
- result of the logarithm
- Throws:
ArithmeticException- if theNumeralis zero or negative, if the base is zero or negative, or if the base is oneNullPointerException- if any of theNumeralsreturnnullforNumeral.getType()IllegalArgumentException- if any of theNumeralsdo not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
min
Returns the minimum of twoNumerals, that is, the Numeral that represents a lesser number. If the Numerals represent the same number, the first Numeral is returned- Parameters:
numeral-Numeralto compareother-Numeralto compare- Returns:
- the lesser of the specified
Numerals - Throws:
NullPointerException- if any of theNumeralsreturnnullforNumeral.getType()IllegalArgumentException- if any of theNumeralsdo not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
max
Returns the maximum of twoNumerals, that is, the Numeral that represents a greater number. If the Numerals represent the same number, the first Numeral is returned- Parameters:
numeral-Numeralto compareother-Numeralto compare- Returns:
- the greater of the specified
Numerals - Throws:
NullPointerException- if any of theNumeralsreturnnullforNumeral.getType()IllegalArgumentException- if any of theNumeralsdo not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
lerp
Linearly interpolates aNumeralbased on a minimum and maximum numeral. The mathematical formula for the operation isnumeral * (max - min) + min. Values smaller than zero and greater than one are allowed.- Parameters:
numeral-Numeralto be interpolatedmin- minimum valuemax- maximum value- Returns:
- result of the linear interpolation
- Throws:
NullPointerException- if any of theNumeralsreturnnullforNumeral.getType()IllegalArgumentException- if any of theNumeralsdo not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
add
- Parameters:
augend- augendaddend- addend- Returns:
- result of the addition
-
add
- Parameters:
augend- augendaddend- addend- Returns:
- result of the addition
-
add
- Parameters:
augend- augendaddend- addend- Returns:
- result of the addition
-
add
- Parameters:
augend- augendaddend- addend- Returns:
- result of the addition
-
add
- Parameters:
augend- augendaddend- addend- Returns:
- result of the addition
-
add
- Parameters:
augend- augendaddend- addend- Returns:
- result of the addition
-
subtract
- Parameters:
minuend- minuendsubtrahend- subtrahend- Returns:
- result of the subtraction
-
subtract
- Parameters:
minuend- minuendsubtrahend- subtrahend- Returns:
- result of the subtraction
-
subtract
- Parameters:
minuend- minuendsubtrahend- subtrahend- Returns:
- result of the subtraction
-
subtract
- Parameters:
minuend- minuendsubtrahend- subtrahend- Returns:
- result of the subtraction
-
subtract
- Parameters:
minuend- minuendsubtrahend- subtrahend- Returns:
- result of the subtraction
-
subtract
- Parameters:
minuend- minuendsubtrahend- subtrahend- Returns:
- result of the subtraction
-
multiply
- Parameters:
multiplicand- multiplicandmultiplier- multiplier- Returns:
- result of the multiplication
-
multiply
- Parameters:
multiplicand- multiplicandmultiplier- multiplier- Returns:
- result of the multiplication
-
multiply
- Parameters:
multiplicand- multiplicandmultiplier- multiplier- Returns:
- result of the multiplication
-
multiply
- Parameters:
multiplicand- multiplicandmultiplier- multiplier- Returns:
- result of the multiplication
-
multiply
- Parameters:
multiplicand- multiplicandmultiplier- multiplier- Returns:
- result of the multiplication
-
multiply
- Parameters:
multiplicand- multiplicandmultiplier- multiplier- Returns:
- result of the multiplication
-
divide
- Parameters:
dividend- dividenddivisor- divisor- Returns:
- result of the division
-
divide
- Parameters:
dividend- dividenddivisor- divisor- Returns:
- result of the division
-
divide
- Parameters:
dividend- dividenddivisor- divisor- Returns:
- result of the division
-
divide
- Parameters:
dividend- dividenddivisor- divisor- Returns:
- result of the division
-
divide
- Parameters:
dividend- dividenddivisor- divisor- Returns:
- result of the division
-
divide
- Parameters:
dividend- dividenddivisor- divisor- Returns:
- result of the division
-
power
- Parameters:
base- baseexponent- exponent- Returns:
- result of the exponentiation
-
power
- Parameters:
base- baseexponent- exponent- Returns:
- result of the exponentiation
-
power
- Parameters:
base- baseexponent- exponent- Returns:
- result of the exponentiation
-
power
- Parameters:
base- baseexponent- exponent- Returns:
- result of the exponentiation
-
power
- Parameters:
base- baseexponent- exponent- Returns:
- result of the exponentiation
-
power
- Parameters:
base- baseexponent- exponent- Returns:
- result of the exponentiation
-
exp
- Parameters:
value- value- Returns:
- natural exponent of the value
-
exp
- Parameters:
value- value- Returns:
- natural exponent of the value
-
exp
- Parameters:
value- exponent- Returns:
- natural exponent of value
-
exp
- Parameters:
value- value- Returns:
- natural exponent of the value
-
exp
- Parameters:
value- value- Returns:
- natural exponent of the value
-
exp
- Parameters:
value- value- Returns:
- natural exponent of the value
-
sqrt
- Parameters:
value- value- Returns:
- square root of value
-
sqrt
- Parameters:
value- value- Returns:
- square root of value
-
sqrt
- Parameters:
value- value- Returns:
- square root of value
-
sqrt
- Parameters:
value- value- Returns:
- square root of value
-
sqrt
- Parameters:
value- value- Returns:
- square root of value
-
sqrt
- Parameters:
value- value- Returns:
- square root of value
-
cbrt
- Parameters:
value- value- Returns:
- cube root of value
-
cbrt
- Parameters:
value- value- Returns:
- cube root of value
-
cbrt
- Parameters:
value- value- Returns:
- cube root of value
-
cbrt
- Parameters:
value- value- Returns:
- cube root of value
-
cbrt
- Parameters:
value- value- Returns:
- cube root of value
-
cbrt
- Parameters:
value- value- Returns:
- cube root of value
-
root
- Parameters:
value- valuebase- base of the root- Returns:
- root of the value in the specified base
-
root
- Parameters:
value- valuebase- base of the root- Returns:
- root of the value in the specified base
-
root
- Parameters:
value- valuebase- base of the root- Returns:
- root of the value in the specified base
-
root
- Parameters:
value- valuebase- base of the root- Returns:
- root of the value in the specified base
-
root
- Parameters:
value- valuebase- base of the root- Returns:
- root of the value in the specified base
-
root
- Parameters:
value- valuebase- base of the root- Returns:
- root of the value in the specified base
-
log
- Parameters:
value- value- Returns:
- natural logarithm of the value
-
log
- Parameters:
value- value- Returns:
- natural logarithm of the value
-
log
- Parameters:
value- value- Returns:
- natural logarithm of the value
-
log
- Parameters:
value- value- Returns:
- natural logarithm of the value
-
log
- Parameters:
value- value- Returns:
- natural logarithm of the value
-
log
- Parameters:
value- value- Returns:
- natural logarithm of the value
-
log2
- Parameters:
value- value- Returns:
- binary logarithm of the value
-
log2
- Parameters:
value- value- Returns:
- binary logarithm of the value
-
log2
- Parameters:
value- value- Returns:
- binary logarithm of the value
-
log2
- Parameters:
value- value- Returns:
- binary logarithm of the value
-
log2
- Parameters:
value- value- Returns:
- binary logarithm of the value
-
log2
- Parameters:
value- value- Returns:
- binary logarithm of the value
-
log10
- Parameters:
value- value- Returns:
- base 10 logarithm of the value
-
log10
- Parameters:
value- value- Returns:
- base 10 logarithm of the value
-
log10
- Parameters:
value- value- Returns:
- base 10 logarithm of the value
-
log10
- Parameters:
value- value- Returns:
- base 10 logarithm of the value
-
log10
- Parameters:
value- value- Returns:
- base 10 logarithm of the value
-
log10
- Parameters:
value- value- Returns:
- base 10 logarithm of the value
-
logN
- Parameters:
value- valuebase- base- Returns:
- logarithm of the value in the specified base
-
logN
- Parameters:
value- valuebase- base- Returns:
- logarithm of the value in the specified base
-
logN
- Parameters:
value- valuebase- base- Returns:
- logarithm of the value in the specified base
-
logN
- Parameters:
value- valuebase- base- Returns:
- logarithm of the value in the specified base
-
logN
- Parameters:
value- valuebase- base- Returns:
- logarithm of the value in the specified base
-
logN
- Parameters:
value- valuebase- base- Returns:
- logarithm of the value in the specified base
-
lerp
- Parameters:
value- value to be interpolatedmin- minimum valuemax- maximum value- Returns:
- result of the linear interpolation
-
lerp
- Parameters:
value- value to be interpolatedmin- minimum valuemax- maximum value- Returns:
- result of the linear interpolation
-
lerp
- Parameters:
value- value to be interpolatedmin- minimum valuemax- maximum value- Returns:
- result of the linear interpolation
-
lerp
- Parameters:
value- value to be interpolatedmin- minimum valuemax- maximum value- Returns:
- result of the linear interpolation
-
lerp
- Parameters:
value- value to be interpolatedmin- minimum valuemax- maximum value- Returns:
- result of the linear interpolation
-
lerp
- Parameters:
value- value to be interpolatedmin- minimum valuemax- maximum value- Returns:
- result of the linear interpolation
-