Apply a Decimal arithmetic operation, returning `Value::Null` on overflow/div-zero.
(a: Decimal, op: BinaryOp, b: Decimal)
| 30 | |
| 31 | /// Apply a Decimal arithmetic operation, returning `Value::Null` on overflow/div-zero. |
| 32 | fn decimal_arith(a: Decimal, op: BinaryOp, b: Decimal) -> Value { |
| 33 | let result = match op { |
| 34 | BinaryOp::Add => a.checked_add(b), |
| 35 | BinaryOp::Sub => a.checked_sub(b), |
| 36 | BinaryOp::Mul => a.checked_mul(b), |
| 37 | BinaryOp::Div => a.checked_div(b), |
| 38 | BinaryOp::Mod => a.checked_rem(b), |
| 39 | _ => return Value::Null, |
| 40 | }; |
| 41 | result.map(Value::Decimal).unwrap_or(Value::Null) |
| 42 | } |
| 43 | |
| 44 | pub(super) fn eval_binary_op(left: &Value, op: BinaryOp, right: &Value) -> Value { |
| 45 | match op { |