Skip to content

java-coding-prodigy/big-math

 
 

Repository files navigation

Build Status Code Coverage Coverity Scan Maven Central

big-math

Java math functions for BigDecimal.

Overview BigDecimalMath

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 for int y

  • 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 a BigDecimal (mantissa * 10^exponent)

  • exponent(BigDecimal) extracts the exponent from a BigDecimal (mantissa * 10^exponent)

  • integralPart(BigDecimal) extract the integral part from a BigDecimal (everything before the decimal point)

  • fractionalPart(BigDecimal) extract the fractional part from a BigDecimal (everything after the decimal point)

Documentation

For the mathematical background and performance analysis please refer to this article:

Some of the implementation details are explained here:

Development

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):

Use in Maven Build

<dependency>
    <groupId>ch.obermuhlner</groupId>
    <artifactId>big-math</artifactId>
    <version>1.0-beta2</version>
</dependency>

Use in Gradle Build

repositories {
  mavenCentral()
}

dependencies {
  compile 'ch.obermuhlner:big-math:1.0-beta2'
}

Performance

The following charts show the time needed to calculate the functions over a range of values with a precision of 300 digits.

sqrt(), root(), exp(), sin(), cos() 0 to 10 sqrt(), root(), exp(), sin(), cos() 0 to 100

exp(), log(), pow() 0 to 10 exp(), log(), pow() 0 to 100

About

Advanced Java BigDecimal math functions (pow, sqrt, log, sin, ...) using arbitrary precision.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Java 99.9%
  • Shell 0.1%