File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -2574,12 +2574,13 @@ macro_rules! int_impl {
25742574 #[ must_use = "this returns the result of the operation, \
25752575 without modifying the original"]
25762576 #[ inline( always) ]
2577+ #[ rustc_allow_const_fn_unstable( const_cmp) ]
25772578 pub const fn signum( self ) -> Self {
2578- match self {
2579- n if n > 0 => 1 ,
2580- 0 => 0 ,
2581- _ => - 1 ,
2582- }
2579+ // Picking the right way to phrase this is complicated
2580+ // (<https://graphics.stanford.edu/~seander/bithacks.html#CopyIntegerSign>)
2581+ // so delegate it to `Ord` which is already producing -1/0/+1
2582+ // exactly like we need and can be the place to deal with the complexity.
2583+ self . cmp ( & 0 ) as _
25832584 }
25842585
25852586 /// Returns `true` if `self` is positive and `false` if the number is zero or
You can’t perform that action at this time.
0 commit comments