fn clamp01(v: f64) -> f64
MATLAB’s min(max(v, 0), 1), which maps NaN to 0 (clamp would keep it)
min(max(v, 0), 1)
clamp