Skip to content

Commit 1a44ffb

Browse files
committed
Add a default impl for Float::clamp
1 parent 2957044 commit 1a44ffb

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/float.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,8 @@ pub trait Float: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
15311531

15321532
/// Clamps a value between a min and max.
15331533
///
1534+
/// **Panics** in debug mode if `!(min <= max)`.
1535+
///
15341536
/// ```
15351537
/// use num_traits::Float;
15361538
///
@@ -1540,7 +1542,9 @@ pub trait Float: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
15401542
///
15411543
/// assert_eq!(x.clamp(y, z), 2.0);
15421544
/// ```
1543-
fn clamp(self, min: Self, max: Self) -> Self;
1545+
fn clamp(self, min: Self, max: Self) -> Self {
1546+
crate::clamp(self, min, max)
1547+
}
15441548

15451549
/// The positive difference of two numbers.
15461550
///

0 commit comments

Comments
 (0)