Skip to content

Commit

Permalink
Add a default impl for Float::clamp
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed May 3, 2024
1 parent 2957044 commit 1a44ffb
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,8 @@ pub trait Float: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {

/// Clamps a value between a min and max.
///
/// **Panics** in debug mode if `!(min <= max)`.
///
/// ```
/// use num_traits::Float;
///
Expand All @@ -1540,7 +1542,9 @@ pub trait Float: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
///
/// 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.
///
Expand Down

0 comments on commit 1a44ffb

Please sign in to comment.