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

Function map_float

nodedb-array/src/coord/normalize.rs:106–120  ·  view source on GitHub ↗
(array: &str, dim: &DimSpec, v: f64, lo: f64, hi: f64, max: u64)

Source from the content-addressed store, hash-verified

104}
105
106fn map_float(array: &str, dim: &DimSpec, v: f64, lo: f64, hi: f64, max: u64) -> ArrayResult<u64> {
107 if !v.is_finite() || v < lo || v > hi {
108 return Err(ArrayError::CoordOutOfDomain {
109 array: array.to_string(),
110 dim: dim.name.clone(),
111 detail: format!("value {v} outside [{lo}, {hi}] or non-finite"),
112 });
113 }
114 let span = hi - lo;
115 if span <= 0.0 {
116 return Ok(0);
117 }
118 let frac = ((v - lo) / span).clamp(0.0, 1.0);
119 Ok((frac * (max as f64)) as u64)
120}
121
122/// String dims fall back to a deterministic hash bucket. Hilbert/Z-order
123/// over strings is inherently lossy — preserves equality, not ordering.

Callers 1

normalize_oneFunction · 0.85

Calls 2

to_stringMethod · 0.80
cloneMethod · 0.45

Tested by

no test coverage detected