src/main/java/com/virgo47/vexpressed/core/ExpressionCalculatorVisitor.java
private Number integerArithmetic(ExprParser.ArithmeticOpContext ctx, long left, int right) {
		switch (ctx.op.getType()) {
			case ExprParser.OP_ADD:
				return narrowNumberResult(left + right);
			case ExprParser.OP_SUB:
				return narrowNumberResult(left - right);
			case ExprParser.OP_MUL:
				return narrowNumberResult(left * right);
			case ExprParser.OP_DIV:
				return narrowNumberResult(divide(new BigDecimal(left), new BigDecimal(right)));
			case ExprParser.OP_IDIV:
				return narrowNumberResult(left / right);
			case ExprParser.OP_REMAINDER:
				return narrowNumberResult(left % right);
			case ExprParser.OP_POW:
				return narrowNumberResult(BigInteger.valueOf(left).pow(right));
			default:
				throw new ExpressionException("Unknown operator " + ctx.op);
		}
	}
/** Left side is made long to prevent overflows. */
Left side is made long to prevent overflows.
Left side is made long to prevent overflows .
private Number integerArithmetic(ExprParser.ArithmeticOpContext ctx, long left, int right) {
		switch (ctx.op.getType()) {
			case ExprParser.OP_ADD:
				return narrowNumberResult(left + right);
			case ExprParser.OP_SUB:
				return narrowNumberResult(left - right);
			case ExprParser.OP_MUL:
				return narrowNumberResult(left * right);
			case ExprParser.OP_DIV:
				return narrowNumberResult(divide(new BigDecimal(left), new BigDecimal(right)));
			case ExprParser.OP_IDIV:
				return narrowNumberResult(left / right);
			case ExprParser.OP_REMAINDER:
				return narrowNumberResult(left % right);
			case ExprParser.OP_POW:
				return narrowNumberResult(BigInteger.valueOf(left).pow(right));
			default:
				throw new ExpressionException("Unknown operator " + ctx.op);
		}
	}
private Number integerArithmetic ( ExprParser . ArithmeticOpContext ctx , long left , int right ) { switch ( ctx . op . getType ( ) ) { case ExprParser . OP_ADD : return narrowNumberResult ( left + right ) ; case ExprParser . OP_SUB : return narrowNumberResult ( left - right ) ; case ExprParser . OP_MUL : return narrowNumberResult ( left * right ) ; case ExprParser . OP_DIV : return narrowNumberResult ( divide ( new BigDecimal ( left ) , new BigDecimal ( right ) ) ) ; case ExprParser . OP_IDIV : return narrowNumberResult ( left / right ) ; case ExprParser . OP_REMAINDER : return narrowNumberResult ( left % right ) ; case ExprParser . OP_POW : return narrowNumberResult ( BigInteger . valueOf ( left ) . pow ( right ) ) ; default : throw new ExpressionException ( "Unknown operator " + ctx . op ) ; } }
Left side is made long to prevent overflows.
Left side is made long to prevent overflows .