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

Function apply

nodedb-array/src/query/elementwise.rs:63–88  ·  view source on GitHub ↗
(l: &CellValue, r: &CellValue, op: BinaryOp)

Source from the content-addressed store, hash-verified

61}
62
63fn apply(l: &CellValue, r: &CellValue, op: BinaryOp) -> CellValue {
64 let (lf, rf) = match (to_f64(l), to_f64(r)) {
65 (Some(a), Some(b)) => (a, b),
66 _ => return passthrough(l, r),
67 };
68 let v = match op {
69 BinaryOp::Add => lf + rf,
70 BinaryOp::Sub => lf - rf,
71 BinaryOp::Mul => lf * rf,
72 BinaryOp::Div => {
73 if rf == 0.0 {
74 return CellValue::Null;
75 }
76 lf / rf
77 }
78 };
79 // Preserve Int64 when both operands were integral and result is
80 // exact — keeps integer attrs from drifting to floats unnecessarily.
81 if let (CellValue::Int64(_), CellValue::Int64(_)) = (l, r)
82 && v.fract() == 0.0
83 && v.is_finite()
84 {
85 return CellValue::Int64(v as i64);
86 }
87 CellValue::Float64(v)
88}
89
90fn passthrough(l: &CellValue, r: &CellValue) -> CellValue {
91 if !l.is_null() {

Callers 1

elementwiseFunction · 0.85

Calls 2

to_f64Function · 0.85
passthroughFunction · 0.85

Tested by

no test coverage detected