File tree Expand file tree Collapse file tree 1 file changed +6
-10
lines changed Expand file tree Collapse file tree 1 file changed +6
-10
lines changed Original file line number Diff line number Diff line change @@ -1416,18 +1416,14 @@ $EndFeature, "
14161416```" ) ,
14171417 #[ stable( feature = "no_panic_abs" , since = "1.13.0" ) ]
14181418 #[ rustc_const_stable( feature = "const_int_methods" , since = "1.32.0" ) ]
1419+ #[ allow_internal_unstable( const_if_match) ]
14191420 #[ inline]
14201421 pub const fn wrapping_abs( self ) -> Self {
1421- // sign is -1 (all ones) for negative numbers, 0 otherwise.
1422- let sign = self >> ( $BITS - 1 ) ;
1423- // For positive self, sign == 0 so the expression is simply
1424- // (self ^ 0).wrapping_sub(0) == self == abs(self).
1425- //
1426- // For negative self, self ^ sign == self ^ all_ones.
1427- // But all_ones ^ self == all_ones - self == -1 - self.
1428- // So for negative numbers, (self ^ sign).wrapping_sub(sign) is
1429- // (-1 - self).wrapping_sub(-1) == -self == abs(self).
1430- ( self ^ sign) . wrapping_sub( sign)
1422+ if self . is_negative( ) {
1423+ self . wrapping_neg( )
1424+ } else {
1425+ self
1426+ }
14311427 }
14321428 }
14331429
You can’t perform that action at this time.
0 commit comments