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 {
2574
2574
#[ must_use = "this returns the result of the operation, \
2575
2575
without modifying the original"]
2576
2576
#[ inline( always) ]
2577
+ #[ rustc_allow_const_fn_unstable( const_cmp) ]
2577
2578
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 _
2583
2584
}
2584
2585
2585
2586
/// 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