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)
| 20 | /// rather than compounding f64 ULP error through further f64 arithmetic) |
| 21 | /// - Other types: `None` |
| 22 | fn 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. |
| 32 | fn decimal_arith(a: Decimal, op: BinaryOp, b: Decimal) -> Value { |