View Javadoc

    1   package org.codehaus.groovy.runtime.typehandling;
    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 absImpl(Number number) {
    15  		return toBigInteger(number).abs();
    16  	}
    17
    18  	protected Number addImpl(Number left, Number right) {
    19  		return toBigInteger(left).add(toBigInteger(right));
    20  	}
    21  	protected Number subtractImpl(Number left, Number right) {
    22  		return toBigInteger(left).subtract(toBigInteger(right));
    23  	}
    24
    25  	protected Number multiplyImpl(Number left, Number right) {
    26  		return toBigInteger(left).multiply(toBigInteger(right));
    27  	}
    28
    29  	protected Number divideImpl(Number left, Number right) {
    30  		return BigDecimalMath.instance.divideImpl(left, right);
    31  	}
    32
    33  	protected int compareToImpl(Number left, Number right) {
    34  		return toBigInteger(left).compareTo(toBigInteger(right));
    35  	}
    36
    37      protected Number intdivImpl(Number left, Number right) {
    38          return toBigInteger(left).divide(toBigInteger(right));
    39      }
    40
    41      protected Number modImpl(Number left, Number right) {
    42          return toBigInteger(left).mod(toBigInteger(right));
    43      }
    44
    45      protected Number negateImpl(Number left) {
    46          return toBigInteger(left).negate();
    47      }
    48
    49      protected Number bitNegateImpl(Number left) {
    50          return toBigInteger(left).not();
    51      }
    52
    53      protected Number orImpl(Number left, Number right) {
    54          return toBigInteger(left).or(toBigInteger(right));
    55      }
    56
    57      protected Number andImpl(Number left, Number right) {
    58          return toBigInteger(left).and(toBigInteger(right));
    59      }
    60
    61      protected Number xorImpl(Number left, Number right) {
    62          return toBigInteger(left).xor(toBigInteger(right));
    63      }
    64  }