Beispiel #1
0
 public void testToStrb() {
   BigNum a = new BigNum(STR);
   String str = null;
   long st = System.currentTimeMillis();
   for (int i = 0; i < MAX_CNT; i++) {
     str = a.toString();
   }
   long ed = System.currentTimeMillis() - st;
   System.out.println(str + ":" + ed + "ms");
   a = null;
 }
Beispiel #2
0
 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;
 }
Beispiel #3
0
 public void testMulb() {
   BigNum a = new BigNum(STR);
   BigNum b = new BigNum(STR);
   long st = System.currentTimeMillis();
   for (int i = 0; i < MAX_CNT2; i++) {
     b = b.multiply(a);
   }
   long ed = System.currentTimeMillis() - st;
   System.out.println(b + ":" + ed + "ms");
   a = null;
   b = null;
 }
Beispiel #4
0
 public void testSubtractb1() {
   BigNum a = new BigNum(STR);
   BigNum b = new BigNum("0.0");
   long st = System.currentTimeMillis();
   for (int i = 0; i < MAX_CNT; i++) {
     b = b.subtract(a);
   }
   long ed = System.currentTimeMillis() - st;
   System.out.println(b + ":" + ed + "ms");
   a = null;
   b = null;
 }
Beispiel #5
0
 public static void test3() {
   BigNum angle = new BigNum("0.0");
   BigNum maxVal = new BigNum("0.25").multiply(BigNum.PI);
   BigNum step = BigNum.PI.divide(new BigNum("12.0"), 40, BigNumRound.HALF_EVENT);
   System.out.print("\t\tInit=" + angle + "\t,MaxValue=" + maxVal + "\t,step=" + step);
   for (; angle.compareTo(maxVal) <= 0; ) {
     System.out.println(
         "\t\tsin("
             + MathBn.toDegrees(angle)
             + ")="
             + MathBn.sin(angle)); // taylorSeriesSine(angle));
     angle = angle.add(step);
   }
 }
Beispiel #6
0
 /**
  * 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;
 }