if (Math.abs(r.doubleValue()) < eps) { break; MathContext mcloc = new MathContext(1 + err2prec(r.doubleValue(), eps)); res = res.add(r.BigDecimalValue(mcloc));
/** * The natural logarithm. * * @param r The main argument, a strictly positive value. * @param mc The requirements on the precision. * @return ln(r). */ static public BigDecimal log(final Rational r, final MathContext mc) { /* the value is undefined if x is negative. */ if (r.compareTo(Rational.ZERO) <= 0) { throw new ArithmeticException("Cannot take log of negative " + r.toString()); } else if (r.compareTo(Rational.ONE) == 0) { return BigDecimal.ZERO; } else { /* log(r+epsr) = log(r)+epsr/r. Convert the precision to an absolute error in the result. * eps contains the required absolute error of the result, epsr/r. */ double eps = prec2err(Math.log(r.doubleValue()), mc.getPrecision()); /* Convert this further into a requirement of the relative precision in r, given that * epsr/r is also the relative precision of r. Add one safety digit. */ MathContext mcloc = new MathContext(1 + err2prec(eps)); final BigDecimal resul = log(r.BigDecimalValue(mcloc)); return resul.round(mc); } } /* log */
for (int k = 1;; k++) { Rational tmp = pk.divide(k); if (tmp.doubleValue() < eps) { break; mcloc = new MathContext(err2prec(tmp.doubleValue(), eps)); BigDecimal c = pk.divide(k).BigDecimalValue(mcloc); if (k % 2 != 0) { for (int k = 1;; k++) { Rational tmp = pk.divide(k); if (tmp.doubleValue() < eps) { break; mcloc = new MathContext(err2prec(tmp.doubleValue(), eps)); BigDecimal c = pk.divide(k).BigDecimalValue(mcloc); log5 = log5.subtract(c); for (int k = 1;; k++) { Rational tmp = pk.divide(k); if (tmp.doubleValue() < eps) { break; mcloc = new MathContext(err2prec(tmp.doubleValue(), eps)); BigDecimal c = pk.divide(k).BigDecimalValue(mcloc); log7 = log7.subtract(c);
if (Math.abs(r.doubleValue()) < eps) { break; MathContext mcloc = new MathContext(1 + err2prec(r.doubleValue(), eps)); res = res.add(r.BigDecimalValue(mcloc));
/** * The natural logarithm. * * @param r The main argument, a strictly positive value. * @param mc The requirements on the precision. * @return ln(r). */ static public BigDecimal log(final Rational r, final MathContext mc) { /* the value is undefined if x is negative. */ if (r.compareTo(Rational.ZERO) <= 0) { throw new ArithmeticException("Cannot take log of negative " + r.toString()); } else if (r.compareTo(Rational.ONE) == 0) { return BigDecimal.ZERO; } else { /* log(r+epsr) = log(r)+epsr/r. Convert the precision to an absolute error in the result. * eps contains the required absolute error of the result, epsr/r. */ double eps = prec2err(Math.log(r.doubleValue()), mc.getPrecision()); /* Convert this further into a requirement of the relative precision in r, given that * epsr/r is also the relative precision of r. Add one safety digit. */ MathContext mcloc = new MathContext(1 + err2prec(eps)); final BigDecimal resul = log(r.BigDecimalValue(mcloc)); return resul.round(mc); } } /* log */
for (int k = 1;; k++) { Rational tmp = pk.divide(k); if (tmp.doubleValue() < eps) { break; mcloc = new MathContext(err2prec(tmp.doubleValue(), eps)); BigDecimal c = pk.divide(k).BigDecimalValue(mcloc); if (k % 2 != 0) { for (int k = 1;; k++) { Rational tmp = pk.divide(k); if (tmp.doubleValue() < eps) { break; mcloc = new MathContext(err2prec(tmp.doubleValue(), eps)); BigDecimal c = pk.divide(k).BigDecimalValue(mcloc); log5 = log5.subtract(c); for (int k = 1;; k++) { Rational tmp = pk.divide(k); if (tmp.doubleValue() < eps) { break; mcloc = new MathContext(err2prec(tmp.doubleValue(), eps)); BigDecimal c = pk.divide(k).BigDecimalValue(mcloc); log7 = log7.subtract(c);