ch.obermuhlner.math.big.internal.PowerTwoNIterator 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;
/**
* {@link PowerIterator} to calculate x2*n.
*/
public class PowerTwoNIterator implements PowerIterator {
private final MathContext mathContext;
private final BigDecimal xPowerTwo;
private BigDecimal powerOfX;
public PowerTwoNIterator(BigDecimal x, MathContext mathContext) {
this.mathContext = mathContext;
xPowerTwo = x.multiply(x, mathContext);
powerOfX = BigDecimal.ONE;
}
@Override
public BigDecimal getCurrentPower() {
return powerOfX;
}
@Override
public void calculateNextPower() {
powerOfX = powerOfX.multiply(xPowerTwo, mathContext);
}
}