Code example for BigInteger

Methods: mod

0
                    return new Double(first.doubleValue() % second.doubleValue());
                } 
                case BIGINTEGER: {
                    BigInteger n1 = toBigInteger(first);
                    BigInteger n2 = toBigInteger(second);
                    return n1.mod(n2);
                } 
                case BIGDECIMAL: {
                    throw new _MiscTemplateException("Can't calculate remainder on BigDecimals"); 
                } 
            } 
            // Make the compiler happy. getCommonClassCode() is guaranteed to  
            // return only above codes, or throw an exception. 
            throw new Error();
        } 
     
        public Number toNumber(String s) {
            return OptimizerUtil.optimizeNumberRepresentation(new BigDecimal(s));
        } 
         
        private static Map createClassCodesMap() {
            Map map = new HashMap(17);
            Integer intcode = new Integer(INTEGER);
            map.put(Byte.class, intcode);
            map.put(Short.class, intcode);
            map.put(Integer.class, intcode);
            map.put(Long.class, new Integer(LONG));
            map.put(Float.class, new Integer(FLOAT));
            map.put(Double.class, new Integer(DOUBLE));
            map.put(BigInteger.class, new Integer(BIGINTEGER));
            map.put(BigDecimal.class, new Integer(BIGDECIMAL));
            return map;
        } 
         
        private static int getClassCode(Number num) throws TemplateException {
            try { 
                return ((Integer)classCodes.get(num.getClass())).intValue();
            } 
            catch(NullPointerException e) {
                if(num == null) {
                    throw new _MiscTemplateException("The Number object was null."); 
                } else { 
                    throw new _MiscTemplateException(new Object[] {
                            "Unknown number type ", num.getClass().getName() });
                } 
            } 
        } 
         
        private static int getCommonClassCode(Number num1, Number num2) throws TemplateException {
            int c1 = getClassCode(num1);
            int c2 = getClassCode(num2);
            int c = c1 > c2 ? c1 : c2;
            // If BigInteger is combined with a Float or Double, the result is a 
            // BigDecimal instead of BigInteger in order not to lose the  
            // fractional parts. If Float is combined with Long, the result is a 
            // Double instead of Float to preserve the bigger bit width. 
            switch(c) {
                case FLOAT: {
                    if((c1 < c2 ? c1 : c2) == LONG) {
                        return DOUBLE;
                    } 
                    break; 
                } 
                case BIGINTEGER: {
                    int min = c1 < c2 ? c1 : c2;
                    if(min == DOUBLE || min == FLOAT) {
                        return BIGDECIMAL;
                    } 
                    break; 
                } 
            } 
            return c;
        } 
         
        private static BigInteger toBigInteger(Number num) {
            return num instanceof BigInteger ? (BigInteger) num : new BigInteger(num.toString());
        } 
    } 
 
    private static BigDecimal toBigDecimal(Number num) {
        try {