ch.obermuhlner.math.big.internal.ExpCalculator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of big-math Show documentation
Show all versions of big-math Show documentation
Math functions for BigDecimal.
package ch.obermuhlner.math.big.internal;
import java.math.BigDecimal;
import java.math.MathContext;
import ch.obermuhlner.math.big.BigRational;
/**
* Calculates exp using the Maclaurin series.
*
*
*
* No argument checking or optimizations are done.
* This implementation is not intended to be called directly.
*/
public class ExpCalculator extends SeriesCalculator {
public static final ExpCalculator INSTANCE = new ExpCalculator();
private int n = 0;
private BigRational oneOverFactorialOfN = BigRational.ONE;
private ExpCalculator() {
// prevent instances
}
@Override
protected BigRational getCurrentFactor() {
return oneOverFactorialOfN;
}
@Override
protected void calculateNextFactor() {
n++;
oneOverFactorialOfN = oneOverFactorialOfN.divide(n);
}
@Override
protected PowerIterator createPowerIterator(BigDecimal x, MathContext mathContext) {
return new PowerNIterator(x, mathContext);
}
}