浏览代码

新增 BigInteger 支持

James 5 年之前
父节点
当前提交
73f114e370

+ 1 - 1
src/main/java/com/jfinal/template/expr/ast/Arith.java

@@ -160,7 +160,7 @@ public class Arith extends Expr {
 		} else if (obj instanceof BigDecimal) {
 			return BIGDECIMAL;
 		} else if (obj instanceof Short || obj instanceof Byte) {
-			return INT;	// short byte 用 int 支持,java 表达式亦如此
+			return INT;			// short byte 用 int 支持,java 表达式亦如此
 		} else if (obj instanceof BigInteger) {
 			return BIGINTEGER;	// 新增 BigInteger 支持
 		}

+ 10 - 1
src/main/java/com/jfinal/template/expr/ast/Compare.java

@@ -17,6 +17,7 @@
 package com.jfinal.template.expr.ast;
 
 import java.math.BigDecimal;
+import java.math.BigInteger;
 import com.jfinal.template.TemplateException;
 import com.jfinal.template.expr.Sym;
 import com.jfinal.template.stat.Location;
@@ -100,6 +101,7 @@ public class Compare extends Expr {
 				// return Double.doubleToLongBits(l.doubleValue()) == Double.doubleToLongBits(r.doubleValue());
 				return l.doubleValue() == r.doubleValue();
 			case Arith.BIGDECIMAL:
+			case Arith.BIGINTEGER:
 				BigDecimal[] bd = Arith.toBigDecimals(l, r);
 				return (bd[0]).compareTo(bd[1]) == 0;
 			}
@@ -127,6 +129,7 @@ public class Compare extends Expr {
 				// return Double.doubleToLongBits(l.doubleValue()) > Double.doubleToLongBits(r.doubleValue());
 				return l.doubleValue() > r.doubleValue();
 			case Arith.BIGDECIMAL:
+			case Arith.BIGINTEGER:
 				BigDecimal[] bd = Arith.toBigDecimals(l, r);
 				return (bd[0]).compareTo(bd[1]) > 0;
 			}
@@ -160,6 +163,7 @@ public class Compare extends Expr {
 				// return Double.doubleToLongBits(l.doubleValue()) >= Double.doubleToLongBits(r.doubleValue());
 				return l.doubleValue() >= r.doubleValue();
 			case Arith.BIGDECIMAL:
+			case Arith.BIGINTEGER:
 				BigDecimal[] bd = Arith.toBigDecimals(l, r);
 				return (bd[0]).compareTo(bd[1]) >= 0;
 			}
@@ -193,6 +197,7 @@ public class Compare extends Expr {
 				// return Double.doubleToLongBits(l.doubleValue()) < Double.doubleToLongBits(r.doubleValue());
 				return l.doubleValue() < r.doubleValue();
 			case Arith.BIGDECIMAL:
+			case Arith.BIGINTEGER:
 				BigDecimal[] bd = Arith.toBigDecimals(l, r);
 				return (bd[0]).compareTo(bd[1]) < 0;
 			}
@@ -226,6 +231,7 @@ public class Compare extends Expr {
 				// return Double.doubleToLongBits(l.doubleValue()) <= Double.doubleToLongBits(r.doubleValue());
 				return l.doubleValue() <= r.doubleValue();
 			case Arith.BIGDECIMAL:
+			case Arith.BIGINTEGER:
 				BigDecimal[] bd = Arith.toBigDecimals(l, r);
 				return (bd[0]).compareTo(bd[1]) <= 0;
 			}
@@ -262,8 +268,11 @@ public class Compare extends Expr {
 		} else if (obj instanceof BigDecimal) {
 			return Arith.BIGDECIMAL;
 		} else if (obj instanceof Short || obj instanceof Byte) {
-			return Arith.INT;	// short byte 用 int 支持,java 表达式亦如此
+			return Arith.INT;			// short byte 用 int 支持,java 表达式亦如此
+		} else if (obj instanceof BigInteger) {
+			return Arith.BIGINTEGER;	// 新增 BigInteger 支持
 		}
+		
 		throw new TemplateException("Unsupported data type: " + obj.getClass().getName(), location);
 	}