Skip to content

Commit fa57078

Browse files
KmolYuanNil Goyette
authored and
Nil Goyette
committed
Improve clamp implementation
1 parent a982f0b commit fa57078

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

src/numeric/impl_float_maths.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,9 @@ where
160160
///
161161
/// # Panics
162162
///
163-
/// Panics if `min > max`, `min` is `NaN`, or `max` is `NaN`.
163+
/// Panics if `!(min <= max)`.
164164
pub fn clamp(&self, min: A, max: A) -> Array<A, D> {
165165
assert!(min <= max, "min must be less than or equal to max");
166-
self.mapv(|v| {
167-
if v < min {
168-
min.clone()
169-
} else if v > max {
170-
max.clone()
171-
} else {
172-
v
173-
}
174-
})
166+
self.mapv(|a| num_traits::clamp(a, min.clone(), max.clone()))
175167
}
176168
}

0 commit comments

Comments
 (0)