File tree Expand file tree Collapse file tree 2 files changed +88
-319
lines changed Expand file tree Collapse file tree 2 files changed +88
-319
lines changed Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments