Java math functions for BigDecimal.
This implementation provides efficient and accurate implementations for:
-
log(BigDecimal, MathContext) -
exp(BigDecimal, MathContext) -
pow(BigDecimal, BigDecimal, MathContext)calculates x^y -
sqrt(BigDecimal, BigDecimal, MathContext) -
root(BigDecimal, BigDecimal, MathContext)calculates the n'th root of x -
sin(BigDecimal, MathContext) -
cos(BigDecimal, MathContext) -
tan(BigDecimal, MathContext) -
asin(BigDecimal, MathContext) -
acos(BigDecimal, MathContext) -
atan(BigDecimal, MathContext) -
sinh(BigDecimal, MathContext) -
cosh(BigDecimal, MathContext) -
tanh(BigDecimal, MathContext) -
asinh(BigDecimal, MathContext) -
acosh(BigDecimal, MathContext) -
atanh(BigDecimal, MathContext) -
pow(BigDecimal, int, MathContext)calculates x^y forinty -
factorial(int, MathContext)calculates n! -
bernoulli(int)calculates Bernoulli numbers -
pi(MathContext)calculates pi to an arbitrary precision -
e(MathContext)calculates e to an arbitrary precision -
mantissa(BigDecimal)extracts the mantissa from aBigDecimal(mantissa * 10^exponent) -
exponent(BigDecimal)extracts the exponent from aBigDecimal(mantissa * 10^exponent) -
integralPart(BigDecimal)extract the integral part from aBigDecimal(everything before the decimal point) -
fractionalPart(BigDecimal)extract the fractional part from aBigDecimal(everything after the decimal point)
For the mathematical background and performance analysis please refer to this article:
Some of the implementation details are explained here:
To use the library you can either download the newest version of the .jar file from the published releases or use the following dependency to Maven Central in your build script (please verify the version number to be the newest release):
<dependency>
<groupId>ch.obermuhlner</groupId>
<artifactId>big-math</artifactId>
<version>1.0-beta2</version>
</dependency>repositories {
mavenCentral()
}
dependencies {
compile 'ch.obermuhlner:big-math:1.0-beta2'
}The following charts show the time needed to calculate the functions over a range of values with a precision of 300 digits.



