@Override protected PowerIterator createPowerIterator(BigDecimal x, MathContext mathContext) { return new PowerTwoNPlusOneIterator(x, mathContext); } }
@Override protected PowerIterator createPowerIterator(BigDecimal x, MathContext mathContext) { return new PowerTwoNIterator(x, mathContext); } }
@Override protected PowerIterator createPowerIterator(BigDecimal x, MathContext mathContext) { return new PowerNIterator(x, mathContext); } }
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(); step = factor.getNumerator().multiply(xToThePower, mathContext).divide(factor.getDenominator(), mathContext); i++; xToThePower = powerIterator.getCurrentPower(); powerIterator.calculateNextPower(); factor = getFactor(i); BigDecimal step2 = factor.getNumerator().multiply(xToThePower, mathContext).divide(factor.getDenominator(), mathContext); step = step.add(step2, mathContext);
public static BigDecimal expReducing(BigDecimal x, MathContext mathContext, int reduce) { MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode()); x = x.divide(valueOf(reduce), mc); BigDecimal result = ExpCalculator.INSTANCE.calculate(x, mc); result = BigDecimalMath.pow(result, reduce, mc); return result.round(mathContext); }
public static BigDecimal asin(BigDecimal x, MathContext mathContext) { if (x.compareTo(ONE) > 0) { throw new ArithmeticException("Illegal asin(x) for x > 1: x = " + x); } if (x.compareTo(MINUS_ONE) < 0) { throw new ArithmeticException("Illegal asin(x) for x < -1: x = " + x); } if (x.signum() == -1) { return asin(x.negate(), mathContext).negate(); } MathContext mc = new MathContext(mathContext.getPrecision() + 6, mathContext.getRoundingMode()); if (x.compareTo(BigDecimal.valueOf(0.707107)) >= 0) { BigDecimal xTransformed = BigDecimalMath.sqrt(ONE.subtract(x.multiply(x, mc), mc), mc); return acos(xTransformed, mathContext); } BigDecimal result = AsinCalculator.INSTANCE.calculate(x, mc); return result.round(mathContext); }
/** * 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); }
/** * Calculates the hyperbolic sine of {@link BigDecimal} x. * * <p>See: <a href="https://en.wikipedia.org/wiki/Hyperbolic_function">Wikipedia: Hyperbolic function</a></p> * * @param x the {@link BigDecimal} to calculate the hyperbolic sine for * @param mathContext the {@link MathContext} used for the result * @return the calculated hyperbolic sine {@link BigDecimal} with the precision specified in the <code>mathContext</code> */ public static BigDecimal sinh(BigDecimal x, MathContext mathContext) { MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode()); BigDecimal result = SinhCalculator.INSTANCE.calculate(x, mc); return result.round(mathContext); }
/** * Calculates the hyperbolic cosine of {@link BigDecimal} x. * * <p>See: <a href="https://en.wikipedia.org/wiki/Hyperbolic_function">Wikipedia: Hyperbolic function</a></p> * * @param x the {@link BigDecimal} to calculate the hyperbolic cosine for * @param mathContext the {@link MathContext} used for the result * @return the calculated hyperbolic cosine {@link BigDecimal} with the precision specified in the <code>mathContext</code> */ public static BigDecimal cosh(BigDecimal x, MathContext mathContext) { MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode()); BigDecimal result = CoshCalculator.INSTANCE.calculate(x, mc); return result.round(mathContext); }
/** * Calculates the cosine (cosinus) of {@link BigDecimal} x. * * <p>See: <a href="http://en.wikipedia.org/wiki/Cosine">Wikipedia: Cosine</a></p> * * @param x the {@link BigDecimal} to calculate the cosine for * @param mathContext the {@link MathContext} used for the result * @return the calculated cosine {@link BigDecimal} */ public static BigDecimal cos(BigDecimal x, MathContext mathContext) { MathContext mc = new MathContext(mathContext.getPrecision() + 6, mathContext.getRoundingMode()); if (x.abs().compareTo(ROUGHLY_TWO_PI) > 0) { BigDecimal twoPi = TWO.multiply(pi(mc), mc); x = x.remainder(twoPi, mc); } BigDecimal result = CosCalculator.INSTANCE.calculate(x, mc); return result.round(mathContext); }
/** * Calculates the sine (sinus) of {@link BigDecimal} x. * * <p>See: <a href="http://en.wikipedia.org/wiki/Sine">Wikipedia: Sine</a></p> * * @param x the {@link BigDecimal} to calculate the sine for * @param mathContext the {@link MathContext} used for the result * @return the calculated sine {@link BigDecimal} with the precision specified in the <code>mathContext</code> */ public static BigDecimal sin(BigDecimal x, MathContext mathContext) { MathContext mc = new MathContext(mathContext.getPrecision() + 6, mathContext.getRoundingMode()); if (x.abs().compareTo(ROUGHLY_TWO_PI) > 0) { BigDecimal twoPi = TWO.multiply(pi(mc), mc); x = x.remainder(twoPi, mc); } BigDecimal result = SinCalculator.INSTANCE.calculate(x, mc); return result.round(mathContext); }
public static BigDecimal exp(BigDecimal x, MathContext mathContext) { MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode()); BigDecimal result = ExpCalculator.INSTANCE.calculate(x, mc); return result.round(mathContext); }
BigDecimal result = AsinCalculator.INSTANCE.calculate(x, mc); return result.round(mathContext);
@Override protected PowerIterator createPowerIterator(BigDecimal x, MathContext mathContext) { return new PowerTwoNPlusOneIterator(x, mathContext); } }
@Override protected PowerIterator createPowerIterator(BigDecimal x, MathContext mathContext) { return new PowerTwoNIterator(x, mathContext); } }
private static BigDecimal expTaylor(BigDecimal x, MathContext mathContext) { MathContext mc = new MathContext(mathContext.getPrecision() + 6, mathContext.getRoundingMode()); x = x.divide(valueOf(256), mc); BigDecimal result = ExpCalculator.INSTANCE.calculate(x, mc); result = BigDecimalMath.pow(result, 256, mc); return result.round(mathContext); }
@Override protected PowerIterator createPowerIterator(BigDecimal x, MathContext mathContext) { return new PowerTwoNPlusOneIterator(x, mathContext); } }