in src/main/java/org/apache/commons/jexl3/JexlArithmetic.java [1284:1328]
public Object divide(final Object left, final Object right) {
if (left == null && right == null) {
return controlNullNullOperands(JexlOperator.DIVIDE);
}
// if both (non-null) args fit as long
final Number ln = asLongNumber(left);
final Number rn = asLongNumber(right);
if (ln != null && rn != null) {
final long x = ln.longValue();
final long y = rn.longValue();
if (y == 0L) {
throw new ArithmeticException("/");
}
final long result = x / y;
return narrowLong(left, right, result);
}
final boolean strictCast = isStrict(JexlOperator.DIVIDE);
// if either are bigdecimal use that type
if (left instanceof BigDecimal || right instanceof BigDecimal) {
final BigDecimal l = toBigDecimal(strictCast, left);
final BigDecimal r = toBigDecimal(strictCast, right);
if (BigDecimal.ZERO.equals(r)) {
throw new ArithmeticException("/");
}
final BigDecimal result = l.divide(r, getMathContext());
return narrowBigDecimal(left, right, result);
}
// if either are floating point (double or float) use double
if (isFloatingPointNumber(left) || isFloatingPointNumber(right)) {
final double l = toDouble(strictCast, left);
final double r = toDouble(strictCast, right);
if (r == 0.0) {
throw new ArithmeticException("/");
}
return l / r;
}
// otherwise treat as integers
final BigInteger l = toBigInteger(strictCast, left);
final BigInteger r = toBigInteger(strictCast, right);
if (BigInteger.ZERO.equals(r)) {
throw new ArithmeticException("/");
}
final BigInteger result = l.divide(r);
return narrowBigInteger(left, right, result);
}