public void testDivb() { BigNum a = new BigNum(STR); BigNum b = new BigNum(STR2); long st = System.currentTimeMillis(); for (int i = 0; i < MAX_CNT2; i++) { b = b.divide(a, 20, BigNumRound.HALF_EVENT); } long ed = System.currentTimeMillis() - st; System.out.println(b + ":" + ed + "ms"); a = null; b = null; }
/** * sin(x) = x - x^3/3! + x^5/5! - x^7/7! +... * * @param radians * @return */ public static BigNum taylorSeriesSine(BigNum radians) { BigNum res = new BigNum("0.0"); BigNum a = new BigNum("-1.0"); BigNum sign = new BigNum("1.0"); for (int i = 1; i < 40; i += 2) { BigNum augend = radians.pow(i).multiply(sign); BigNum fac = new BigNum(i).factorial(); BigNum b = augend.divide(fac, 40, BigNumRound.HALF_EVENT); res = res.add(b); sign = sign.multiply(a); } return res; }