MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / decimal_arith

Function decimal_arith

nodedb-query/src/expr/binary.rs:32–42  ·  view source on GitHub ↗

Apply a Decimal arithmetic operation, returning `Value::Null` on overflow/div-zero.

(a: Decimal, op: BinaryOp, b: Decimal)

Source from the content-addressed store, hash-verified

30
31/// Apply a Decimal arithmetic operation, returning `Value::Null` on overflow/div-zero.
32fn 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
44pub(super) fn eval_binary_op(left: &Value, op: BinaryOp, right: &Value) -> Value {
45 match op {

Callers 1

eval_binary_opFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected