pub trait Clamp {
// Required method
fn kernel_clamp(self, min: &Self, max: &Self) -> Self;
}Required Methods§
Sourcefn kernel_clamp(self, min: &Self, max: &Self) -> Self
fn kernel_clamp(self, min: &Self, max: &Self) -> Self
Clamp the value within the specified bounds.
Returns max if self is greater than max, and min if self is less than min.
Otherwise this returns self.
Note that this function returns NaN if the initial value was NaN as well.
§Panics
Panics if min > max, min is NaN, or max is NaN.
use num_valid::functions::Clamp;
assert!((-3.0f64).kernel_clamp(&-2.0, &1.0) == -2.0);
assert!((0.0f64).kernel_clamp(&-2.0, &1.0) == 0.0);
assert!((2.0f64).kernel_clamp(&-2.0, &1.0) == 1.0);
assert!((f64::NAN).kernel_clamp(&-2.0, &1.0).is_nan());Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl Clamp for f64
impl Clamp for f64
Source§fn kernel_clamp(self, min: &Self, max: &Self) -> Self
fn kernel_clamp(self, min: &Self, max: &Self) -> Self
Clamp the value within the specified bounds.
Returns max if self is greater than max, and min if self is less than min.
Otherwise this returns self.
Note that this function returns NaN if the initial value was NaN as well.
§Panics
Panics if min > max, min is NaN, or max is NaN.
use num_valid::functions::Clamp;
assert!((-3.0f64).kernel_clamp(&-2.0, &1.0) == -2.0);
assert!((0.0f64).kernel_clamp(&-2.0, &1.0) == 0.0);
assert!((2.0f64).kernel_clamp(&-2.0, &1.0) == 1.0);
assert!((f64::NAN).kernel_clamp(&-2.0, &1.0).is_nan());