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

Function to_value_number

nodedb-query/src/value_ops.rs:106–114  ·  view source on GitHub ↗

Convert an f64 to a Value, preferring integer representation. Returns `Null` for NaN/Infinity.

(n: f64)

Source from the content-addressed store, hash-verified

104///
105/// Returns `Null` for NaN/Infinity.
106pub fn to_value_number(n: f64) -> Value {
107 if n.is_nan() || n.is_infinite() {
108 Value::Null
109 } else if n.fract() == 0.0 && n.abs() < i64::MAX as f64 {
110 Value::Integer(n as i64)
111 } else {
112 Value::Float(n)
113 }
114}
115
116#[cfg(test)]
117mod tests {

Callers 5

eval_geo_functionFunction · 0.85
eval_scopeMethod · 0.85
eval_binary_opFunction · 0.85
try_evalFunction · 0.85
try_evalFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected