final double eps = xUlpDbl / 2. / Math.pow(Math.sin(xDbl), 2.);
final BigDecimal xhighpr = scalePrec(res, 2);
final BigDecimal xhighprSq = multiplyRound(xhighpr, xhighpr);
MathContext mc = new MathContext(err2prec(xhighpr.doubleValue(), eps));
BigDecimal resul = BigDecimal.ONE.divide(xhighpr, mc);
/* x^(2i-1) */
BigDecimal xpowi = xhighpr;
Bernoulli b = new Bernoulli();
/* 2^(2i) */
BigInteger fourn = new BigInteger("4");
/* (2i)! */
BigInteger fac = BigInteger.ONE;
for (int i = 1; ; i++) {
Rational f = b.at(2 * i);
fac = fac.multiply(new BigInteger("" + (2 * i))).multiply(new BigInteger("" + (2 * i - 1)));
f = f.multiply(fourn).divide(fac);
BigDecimal c = multiplyRound(xpowi, f);
if (i % 2 == 0)
resul = resul.add(c);
else
resul = resul.subtract(c);
if (Math.abs(c.doubleValue()) < 0.1 * eps)
break;
fourn = fourn.shiftLeft(2);
xpowi = multiplyRound(xpowi, xhighprSq);
}
mc = new MathContext(err2prec(resul.doubleValue(), eps));
return resul.round(mc);
}
} /* BigDecimalMath.cot */