KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > groovy > runtime > BigIntegerMath


1 package org.codehaus.groovy.runtime;
2
3 /**
4  * BigInteger NumberMath operations
5  *
6  * @author Steve Goetze
7  */

8 public class BigIntegerMath extends NumberMath {
9
10     protected static BigIntegerMath instance = new BigIntegerMath();
11     
12     private BigIntegerMath() {}
13
14     protected Number JavaDoc absImpl(Number JavaDoc number) {
15         return toBigInteger(number).abs();
16     }
17     
18     protected Number JavaDoc addImpl(Number JavaDoc left, Number JavaDoc right) {
19         return toBigInteger(left).add(toBigInteger(right));
20     }
21
22     protected Number JavaDoc subtractImpl(Number JavaDoc left, Number JavaDoc right) {
23         return toBigInteger(left).subtract(toBigInteger(right));
24     }
25
26     protected Number JavaDoc multiplyImpl(Number JavaDoc left, Number JavaDoc right) {
27         return toBigInteger(left).multiply(toBigInteger(right));
28     }
29
30     protected Number JavaDoc divideImpl(Number JavaDoc left, Number JavaDoc right) {
31         return BigDecimalMath.instance.divideImpl(left, right);
32     }
33     
34     protected int compareToImpl(Number JavaDoc left, Number JavaDoc right) {
35         return toBigInteger(left).compareTo(toBigInteger(right));
36     }
37
38     protected Number JavaDoc andImpl(Number JavaDoc left, Number JavaDoc right) {
39         return toBigInteger(left).and(toBigInteger(right));
40     }
41     
42     protected Number JavaDoc intdivImpl(Number JavaDoc left, Number JavaDoc right) {
43         return toBigInteger(left).divide(toBigInteger(right));
44     }
45     
46     protected Number JavaDoc modImpl(Number JavaDoc left, Number JavaDoc right) {
47         return toBigInteger(left).mod(toBigInteger(right));
48     }
49     
50     protected Number JavaDoc negateImpl(Number JavaDoc left) {
51         return toBigInteger(left).negate();
52     }
53
54     protected Number JavaDoc orImpl(Number JavaDoc left, Number JavaDoc right) {
55         return toBigInteger(left).or(toBigInteger(right));
56     }
57 }
58
Popular Tags