1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// restrain value use num_traits::Float; pub(crate) fn clip<F>(f: F, max: F) -> F where F: Float + num_traits::FromPrimitive, { if f > max { log::trace!("truncated >"); max } else if f < -max { log::trace!("truncated <"); -max } else { f } } // end clip