Skip to content

Commit 7d5e997

Browse files
committed
address reviewer comments
1 parent d7d5999 commit 7d5e997

File tree

2 files changed

+88
-319
lines changed

2 files changed

+88
-319
lines changed

library/core/src/num/int_macros.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3876,12 +3876,11 @@ macro_rules! int_impl {
38763876
#[unstable(feature = "clamp_magnitude", issue = "148519")]
38773877
#[inline]
38783878
pub fn clamp_magnitude(self, limit: $UnsignedT) -> Self {
3879-
// Use try_into to handle cases where `limit` is larger than `Self::MAX`.
3880-
let positive_limit = limit.try_into().unwrap_or(Self::MAX);
3881-
// By capping `positive_limit` at `Self::MAX`, we ensure the range is symmetric.
3882-
// `-positive_limit` is thus always representable.
3883-
let negative_limit = -positive_limit;
3884-
self.clamp(negative_limit, positive_limit)
3879+
if let Ok(limit) = limit.try_into() {
3880+
self.clamp(-limit, limit)
3881+
} else {
3882+
self
3883+
}
38853884
}
38863885
}
38873886
}

0 commit comments

Comments
 (0)