From 1a44ffb9deb4d76988b6ea6bc2767ed40264aac3 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 3 May 2024 13:44:21 -0700 Subject: [PATCH] Add a default impl for `Float::clamp` --- src/float.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/float.rs b/src/float.rs index 71102f2..d0d21a5 100644 --- a/src/float.rs +++ b/src/float.rs @@ -1531,6 +1531,8 @@ pub trait Float: Num + Copy + NumCast + PartialOrd + Neg { /// Clamps a value between a min and max. /// + /// **Panics** in debug mode if `!(min <= max)`. + /// /// ``` /// use num_traits::Float; /// @@ -1540,7 +1542,9 @@ pub trait Float: Num + Copy + NumCast + PartialOrd + Neg { /// /// assert_eq!(x.clamp(y, z), 2.0); /// ``` - fn clamp(self, min: Self, max: Self) -> Self; + fn clamp(self, min: Self, max: Self) -> Self { + crate::clamp(self, min, max) + } /// The positive difference of two numbers. ///