Given some arbitrary float value, what's an idiomatic way of limiting that value to a min/max range? I.e. if you provide a value under the minimum, the minimum range value is returned, and if you provide a value over the maximum, the maximum range value is returned. Otherwise the original float value is returned.
I thought this approach would work, but it's not giving me the correct values:
fn main(){
dbg!(min_max(150.0, 0.0, 100.0));
//because 150.0 is greater than 100.0, should return 100.0
//currently returns 0.0
dbg!(min_max(-100.0, 0.0, 100.0));
//becuase -100.0 is below the minimum value of 0.0, should return 0.0
//currently returns 0.0
}
fn min_max(val: f32, min: f32, max: f32)->f32{
return val.max(max).min(min);
}