/** * Returns the factor of the term with specified index. * * @param index the index (starting with 0) * @return the factor of the specified term */ protected BigRational getFactor(int index) { while (factors.size() <= index) { BigRational factor = getCurrentFactor(); factors.add(factor); calculateNextFactor(); } return factors.get(index); }
BigDecimal acceptableError = ONE.movePointLeft(mathContext.getPrecision() + 1); PowerIterator powerIterator = createPowerIterator(x, mathContext); int i = 0; do { BigRational factor = getFactor(i); BigDecimal xToThePower = powerIterator.getCurrentPower(); powerIterator.calculateNextPower(); xToThePower = powerIterator.getCurrentPower(); powerIterator.calculateNextPower(); factor = getFactor(i); BigDecimal step2 = factor.getNumerator().multiply(xToThePower, mathContext).divide(factor.getDenominator(), mathContext); step = step.add(step2, mathContext);