1 33 package net.sf.jga.fn.arithmetic; 34 35 import java.math.BigInteger ; 36 37 44 45 class BigIntMath implements IntegerArithmetic<BigInteger > { 46 47 static final long serialVersionUID = 8004298803104674966L; 48 49 53 54 public BigInteger valueOf(Number value) throws IllegalArgumentException { 55 return BigInteger.valueOf(value.longValue()); 56 } 57 58 61 62 public BigInteger zero() { 63 return BigInteger.ZERO; 64 } 65 66 69 70 public BigInteger one() { 71 return BigInteger.ONE; 72 } 73 74 78 79 public BigInteger plus (BigInteger x, BigInteger y) { 80 return x.add(y); 81 } 82 83 87 88 public BigInteger minus (BigInteger x, BigInteger y) { 89 return x.subtract(y); 90 } 91 92 96 97 public BigInteger multiplies (BigInteger x, BigInteger y){ 98 return x.multiply(y); 99 } 100 101 105 106 public BigInteger divides (BigInteger x, BigInteger y) { 107 return x.divide(y); 108 } 109 110 114 115 public BigInteger negate (BigInteger x) { 116 return x.negate(); 117 } 118 119 123 124 public BigInteger modulus (BigInteger x, BigInteger y) { 125 return x.mod(y); 126 } 127 128 132 133 public BigInteger and (BigInteger x, BigInteger y) { 134 return x.and(y); 135 } 136 137 141 142 public BigInteger or (BigInteger x, BigInteger y) { 143 return x.or(y); 144 } 145 146 150 151 public BigInteger xor (BigInteger x, BigInteger y) { 152 return x.xor(y); 153 } 154 155 159 160 public BigInteger not (BigInteger x) { 161 return x.not(); 162 } 163 164 167 168 public BigInteger shiftLeft(BigInteger x, Integer y) { 169 return x.shiftLeft(y.intValue()); 170 } 171 172 175 176 public BigInteger signedShiftRight(BigInteger x, Integer y) { 177 return x.shiftRight(y.intValue()); 178 } 179 180 184 185 public BigInteger unsignedShiftRight(BigInteger x, Integer y) { 186 String msg = "BigInteger cannot support unsigned shift"; 187 throw new UnsupportedOperationException (msg); 188 } 189 } 190 | Popular Tags |