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

Function value_to_decimal

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

Coerce a `Value` to `Decimal` for precise arithmetic. - `Decimal`: identity - `Integer`: exact conversion via `Decimal::from` - `Float`: best-effort via `Decimal::try_from` (preserves fractional digits rather than compounding f64 ULP error through further f64 arithmetic) - Other types: `None`

(v: &Value)

Source from the content-addressed store, hash-verified

20/// rather than compounding f64 ULP error through further f64 arithmetic)
21/// - Other types: `None`
22fn value_to_decimal(v: &Value) -> Option<Decimal> {
23 match v {
24 Value::Decimal(d) => Some(*d),
25 Value::Integer(i) => Some(Decimal::from(*i)),
26 Value::Float(f) => Decimal::try_from(*f).ok(),
27 _ => None,
28 }
29}
30
31/// Apply a Decimal arithmetic operation, returning `Value::Null` on overflow/div-zero.
32fn decimal_arith(a: Decimal, op: BinaryOp, b: Decimal) -> Value {

Callers 1

eval_binary_opFunction · 0.85

Calls 1

okMethod · 0.45

Tested by

no test coverage detected