public class BigDecimalMath
extends java.lang.Object
BigDecimals.| Modifier and Type | Method and Description |
|---|---|
static java.math.BigDecimal |
acos(java.math.BigDecimal x,
java.math.MathContext mathContext)
Calculates the arc cosine (inverted cosine) of
BigDecimal x. |
static java.math.BigDecimal |
acosh(java.math.BigDecimal x,
java.math.MathContext mathContext)
Calculates the arc hyperbolic cosine (inverse hyperbolic cosine) of
BigDecimal x. |
static java.math.BigDecimal |
acot(java.math.BigDecimal x,
java.math.MathContext mathContext)
Calculates the inverse cotangens (arc cotangens) of
BigDecimal x. |
static java.math.BigDecimal |
acoth(java.math.BigDecimal x,
java.math.MathContext mathContext)
Calculates the arc hyperbolic cotangens (inverse hyperbolic cotangens) of
BigDecimal x. |
static java.math.BigDecimal |
asin(java.math.BigDecimal x,
java.math.MathContext mathContext)
Calculates the arc sine (inverted sine) of
BigDecimal x. |
static java.math.BigDecimal |
asinh(java.math.BigDecimal x,
java.math.MathContext mathContext)
Calculates the arc hyperbolic sine (inverse hyperbolic sine) of
BigDecimal x. |
static java.math.BigDecimal |
atan(java.math.BigDecimal x,
java.math.MathContext mathContext)
Calculates the arc tangens (inverted tangens) of
BigDecimal x. |
static java.math.BigDecimal |
atan2(java.math.BigDecimal y,
java.math.BigDecimal x,
java.math.MathContext mathContext)
Calculates the arc tangens (inverted tangens) of
BigDecimal y / x in the range -pi to pi. |
static java.math.BigDecimal |
atanh(java.math.BigDecimal x,
java.math.MathContext mathContext)
Calculates the arc hyperbolic tangens (inverse hyperbolic tangens ) of
BigDecimal x. |
static java.math.BigDecimal |
bernoulli(int n,
java.math.MathContext mathContext)
Calculates the Bernoulli number for the specified index.
|
static java.math.BigDecimal |
cos(java.math.BigDecimal x,
java.math.MathContext mathContext)
Calculates the cosine (cosinus) of
BigDecimal x. |
static java.math.BigDecimal |
cosh(java.math.BigDecimal x,
java.math.MathContext mathContext)
Calculates the hyperbolic cosine of
BigDecimal x. |
static java.math.BigDecimal |
cot(java.math.BigDecimal x,
java.math.MathContext mathContext)
Calculates the cotangens of
BigDecimal x. |
static java.math.BigDecimal |
coth(java.math.BigDecimal x,
java.math.MathContext mathContext)
Calculates the hyperbolic cotangens of
BigDecimal x. |
static java.math.BigDecimal |
e(java.math.MathContext mathContext)
Returns the number e.
|
static java.math.BigDecimal |
exp(java.math.BigDecimal x,
java.math.MathContext mathContext)
Calculates the natural exponent of
BigDecimal x (ex). |
static int |
exponent(java.math.BigDecimal value)
Returns the exponent of the specified
BigDecimal written as mantissa * 10exponent. |
static java.math.BigDecimal |
factorial(int n)
Calculates the factorial of the specified
BigDecimal. |
static java.math.BigDecimal |
fractionalPart(java.math.BigDecimal value)
Returns the fractional part of the specified
BigDecimal (right of the decimal point). |
static java.math.BigDecimal |
integralPart(java.math.BigDecimal value)
Returns the integral part of the specified
BigDecimal (left of the decimal point). |
static boolean |
isDoubleValue(java.math.BigDecimal value)
Returns whether the specified
BigDecimal value can be represented as double. |
static boolean |
isIntValue(java.math.BigDecimal value)
Returns whether the specified
BigDecimal value can be represented as int. |
static boolean |
isLongValue(java.math.BigDecimal value)
Returns whether the specified
BigDecimal value can be represented as long. |
static java.math.BigDecimal |
log(java.math.BigDecimal x,
java.math.MathContext mathContext)
Calculates the natural logarithm of
BigDecimal x. |
static java.math.BigDecimal |
log10(java.math.BigDecimal x,
java.math.MathContext mathContext)
Calculates the logarithm of
BigDecimal x to the base 10. |
static java.math.BigDecimal |
log2(java.math.BigDecimal x,
java.math.MathContext mathContext)
Calculates the logarithm of
BigDecimal x to the base 2. |
static java.math.BigDecimal |
mantissa(java.math.BigDecimal value)
Returns the mantissa of the specified
BigDecimal written as mantissa * 10exponent. |
static java.math.BigDecimal |
pi(java.math.MathContext mathContext)
Returns the number pi.
|
static java.math.BigDecimal |
pow(java.math.BigDecimal x,
java.math.BigDecimal y,
java.math.MathContext mathContext)
Calculates
BigDecimal x to the power of BigDecimal y (xy). |
static java.math.BigDecimal |
pow(java.math.BigDecimal x,
long y,
java.math.MathContext mathContext)
Calculates
BigDecimal x to the power of long y (xy). |
static java.math.BigDecimal |
root(java.math.BigDecimal x,
java.math.BigDecimal n,
java.math.MathContext mathContext)
Calculates the n'th root of
BigDecimal x. |
static java.math.BigDecimal |
sin(java.math.BigDecimal x,
java.math.MathContext mathContext)
Calculates the sine (sinus) of
BigDecimal x. |
static java.math.BigDecimal |
sinh(java.math.BigDecimal x,
java.math.MathContext mathContext)
Calculates the hyperbolic sine of
BigDecimal x. |
static java.math.BigDecimal |
sqrt(java.math.BigDecimal x,
java.math.MathContext mathContext)
Calculates the square root of
BigDecimal x. |
static java.math.BigDecimal |
tan(java.math.BigDecimal x,
java.math.MathContext mathContext)
Calculates the tangens of
BigDecimal x. |
static java.math.BigDecimal |
tanh(java.math.BigDecimal x,
java.math.MathContext mathContext)
Calculates the hyperbolic tangens of
BigDecimal x. |
public static boolean isIntValue(java.math.BigDecimal value)
BigDecimal value can be represented as int.
If this returns true you can call BigDecimal.intValueExact() without fear of an ArithmeticException.
value - the BigDecimal to checktrue if the value can be represented as int valuepublic static boolean isLongValue(java.math.BigDecimal value)
BigDecimal value can be represented as long.
If this returns true you can call BigDecimal.longValueExact() without fear of an ArithmeticException.
value - the BigDecimal to checktrue if the value can be represented as long valuepublic static boolean isDoubleValue(java.math.BigDecimal value)
BigDecimal value can be represented as double.
If this returns true you can call BigDecimal.doubleValue()
without fear of getting Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY as result.
Example: BigDecimalMath.isDoubleValue(new BigDecimal("1E309")) returns false,
because new BigDecimal("1E309").doubleValue() returns Infinity.
Note: This method does not check for possible loss of precision.
For example BigDecimalMath.isDoubleValue(new BigDecimal("1.23400000000000000000000000000000001")) will return true,
because new BigDecimal("1.23400000000000000000000000000000001").doubleValue() returns a valid double value,
although it loses precision and returns 1.234.
BigDecimalMath.isDoubleValue(new BigDecimal("1E-325")) will return true
although this value is smaller than Double.MIN_VALUE (and therefore outside the range of values that can be represented as double)
because new BigDecimal("1E-325").doubleValue() returns 0 which is a legal value with loss of precision.
value - the BigDecimal to checktrue if the value can be represented as double valuepublic static java.math.BigDecimal mantissa(java.math.BigDecimal value)
BigDecimal written as mantissa * 10exponent.
The mantissa is defined as having exactly 1 digit before the decimal point.
value - the BigDecimalexponent(BigDecimal)public static int exponent(java.math.BigDecimal value)
BigDecimal written as mantissa * 10exponent.
The mantissa is defined as having exactly 1 digit before the decimal point.
value - the BigDecimalmantissa(BigDecimal)public static java.math.BigDecimal integralPart(java.math.BigDecimal value)
BigDecimal (left of the decimal point).value - the BigDecimalfractionalPart(BigDecimal)public static java.math.BigDecimal fractionalPart(java.math.BigDecimal value)
BigDecimal (right of the decimal point).value - the BigDecimalintegralPart(BigDecimal)public static java.math.BigDecimal factorial(int n)
BigDecimal.
factorial = 1 * 2 * 3 * ... n
n - the BigDecimalBigDecimaljava.lang.ArithmeticException - if x < 0public static java.math.BigDecimal bernoulli(int n,
java.math.MathContext mathContext)
This function calculates the first Bernoulli numbers and therefore bernoulli(1) returns -0.5
Note that bernoulli(x) for all odd x > 1 returns 0
n - the index of the Bernoulli number to be calculated (starting at 0)mathContext - the MathContext used for the resultjava.lang.ArithmeticException - if x < 0public static java.math.BigDecimal pow(java.math.BigDecimal x,
java.math.BigDecimal y,
java.math.MathContext mathContext)
BigDecimal x to the power of BigDecimal y (xy).x - the BigDecimal value to take to the powery - the BigDecimal value to serve as exponentmathContext - the MathContext used for the resultmathContextpublic static java.math.BigDecimal pow(java.math.BigDecimal x,
long y,
java.math.MathContext mathContext)
BigDecimal x to the power of long y (xy).
The implementation tries to minimize the number of multiplications of x (using squares whenever possible).
x - the BigDecimal value to take to the powery - the long value to serve as exponentmathContext - the MathContext used for the resultmathContextpublic static java.math.BigDecimal sqrt(java.math.BigDecimal x,
java.math.MathContext mathContext)
BigDecimal x.
x - the BigDecimal value to calculate the square rootmathContext - the MathContext used for the resultmathContextjava.lang.ArithmeticException - if x < 0public static java.math.BigDecimal root(java.math.BigDecimal x,
java.math.BigDecimal n,
java.math.MathContext mathContext)
BigDecimal x.
x - the BigDecimal value to calculate the n'th rootn - the BigDecimal defining the rootmathContext - the MathContext used for the resultmathContextjava.lang.ArithmeticException - if x < 0public static java.math.BigDecimal log(java.math.BigDecimal x,
java.math.MathContext mathContext)
BigDecimal x.
x - the BigDecimal to calculate the natural logarithm formathContext - the MathContext used for the resultBigDecimal with the precision specified in the mathContextjava.lang.ArithmeticException - if x <= 0public static java.math.BigDecimal log2(java.math.BigDecimal x,
java.math.MathContext mathContext)
BigDecimal x to the base 2.x - the BigDecimal to calculate the logarithm base 2 formathContext - the MathContext used for the resultBigDecimal to the base 2 with the precision specified in the mathContextjava.lang.ArithmeticException - if x <= 0public static java.math.BigDecimal log10(java.math.BigDecimal x,
java.math.MathContext mathContext)
BigDecimal x to the base 10.x - the BigDecimal to calculate the logarithm base 10 formathContext - the MathContext used for the resultBigDecimal to the base 10 with the precision specified in the mathContextjava.lang.ArithmeticException - if x <= 0public static java.math.BigDecimal pi(java.math.MathContext mathContext)
See Wikipedia: Pi
mathContext - the MathContext used for the resultmathContextpublic static java.math.BigDecimal e(java.math.MathContext mathContext)
mathContext - the MathContext used for the resultmathContextpublic static java.math.BigDecimal exp(java.math.BigDecimal x,
java.math.MathContext mathContext)
BigDecimal x (ex).
See: Wikipedia: Exponent
x - the BigDecimal to calculate the exponent formathContext - the MathContext used for the resultBigDecimal with the precision specified in the mathContextpublic static java.math.BigDecimal sin(java.math.BigDecimal x,
java.math.MathContext mathContext)
BigDecimal x.
See: Wikipedia: Sine
x - the BigDecimal to calculate the sine formathContext - the MathContext used for the resultBigDecimal with the precision specified in the mathContextpublic static java.math.BigDecimal asin(java.math.BigDecimal x,
java.math.MathContext mathContext)
BigDecimal x.
See: Wikipedia: Arcsine
x - the BigDecimal to calculate the arc sine formathContext - the MathContext used for the resultBigDecimal with the precision specified in the mathContextjava.lang.ArithmeticException - if x > 1 or x < -1public static java.math.BigDecimal cos(java.math.BigDecimal x,
java.math.MathContext mathContext)
BigDecimal x.
See: Wikipedia: Cosine
x - the BigDecimal to calculate the cosine formathContext - the MathContext used for the resultBigDecimalpublic static java.math.BigDecimal acos(java.math.BigDecimal x,
java.math.MathContext mathContext)
BigDecimal x.
See: Wikipedia: Arccosine
x - the BigDecimal to calculate the arc cosine formathContext - the MathContext used for the resultBigDecimal with the precision specified in the mathContextjava.lang.ArithmeticException - if x > 1 or x < -1public static java.math.BigDecimal tan(java.math.BigDecimal x,
java.math.MathContext mathContext)
BigDecimal x.
See: Wikipedia: Tangens
x - the BigDecimal to calculate the tangens formathContext - the MathContext used for the resultBigDecimal with the precision specified in the mathContextpublic static java.math.BigDecimal atan(java.math.BigDecimal x,
java.math.MathContext mathContext)
BigDecimal x.
x - the BigDecimal to calculate the arc tangens formathContext - the MathContext used for the resultBigDecimal with the precision specified in the mathContextpublic static java.math.BigDecimal atan2(java.math.BigDecimal y,
java.math.BigDecimal x,
java.math.MathContext mathContext)
BigDecimal y / x in the range -pi to pi.
This is useful to calculate the angle theta from the conversion of rectangular
coordinates (x, y) to polar coordinates (r, theta).
See: Wikipedia: Atan2
y - the BigDecimalx - the BigDecimalmathContext - the MathContext used for the resultBigDecimal with the precision specified in the mathContextjava.lang.ArithmeticException - if x = 0 and y = 0public static java.math.BigDecimal cot(java.math.BigDecimal x,
java.math.MathContext mathContext)
BigDecimal x.
See: Wikipedia: Cotangens
x - the BigDecimal to calculate the cotangens formathContext - the MathContext used for the resultBigDecimal with the precision specified in the mathContextjava.lang.ArithmeticException - if x = 0public static java.math.BigDecimal acot(java.math.BigDecimal x,
java.math.MathContext mathContext)
BigDecimal x.
x - the BigDecimal to calculate the arc cotangens formathContext - the MathContext used for the resultBigDecimal with the precision specified in the mathContextpublic static java.math.BigDecimal sinh(java.math.BigDecimal x,
java.math.MathContext mathContext)
BigDecimal x.
x - the BigDecimal to calculate the hyperbolic sine formathContext - the MathContext used for the resultBigDecimal with the precision specified in the mathContextpublic static java.math.BigDecimal cosh(java.math.BigDecimal x,
java.math.MathContext mathContext)
BigDecimal x.
x - the BigDecimal to calculate the hyperbolic cosine formathContext - the MathContext used for the resultBigDecimal with the precision specified in the mathContextpublic static java.math.BigDecimal tanh(java.math.BigDecimal x,
java.math.MathContext mathContext)
BigDecimal x.
x - the BigDecimal to calculate the hyperbolic tangens formathContext - the MathContext used for the resultBigDecimal with the precision specified in the mathContextpublic static java.math.BigDecimal coth(java.math.BigDecimal x,
java.math.MathContext mathContext)
BigDecimal x.
x - the BigDecimal to calculate the hyperbolic cotangens formathContext - the MathContext used for the resultBigDecimal with the precision specified in the mathContextpublic static java.math.BigDecimal asinh(java.math.BigDecimal x,
java.math.MathContext mathContext)
BigDecimal x.
x - the BigDecimal to calculate the arc hyperbolic sine formathContext - the MathContext used for the resultBigDecimal with the precision specified in the mathContextpublic static java.math.BigDecimal acosh(java.math.BigDecimal x,
java.math.MathContext mathContext)
BigDecimal x.
x - the BigDecimal to calculate the arc hyperbolic cosine formathContext - the MathContext used for the resultBigDecimal with the precision specified in the mathContextpublic static java.math.BigDecimal atanh(java.math.BigDecimal x,
java.math.MathContext mathContext)
BigDecimal x.
x - the BigDecimal to calculate the arc hyperbolic tanges formathContext - the MathContext used for the resultBigDecimal with the precision specified in the mathContextpublic static java.math.BigDecimal acoth(java.math.BigDecimal x,
java.math.MathContext mathContext)
BigDecimal x.
x - the BigDecimal to calculate the arc hyperbolic cotangens formathContext - the MathContext used for the resultBigDecimal with the precision specified in the mathContext