Skip to content

Commit d88f979

Browse files
committed
hack signum as well
1 parent 8cda8df commit d88f979

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

library/core/src/num/int_macros.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2603,13 +2603,16 @@ macro_rules! int_impl {
26032603
#[must_use = "this returns the result of the operation, \
26042604
without modifying the original"]
26052605
#[inline(always)]
2606-
#[rustc_allow_const_fn_unstable(const_cmp)]
26072606
pub const fn signum(self) -> Self {
26082607
// Picking the right way to phrase this is complicated
26092608
// (<https://graphics.stanford.edu/~seander/bithacks.html#CopyIntegerSign>)
26102609
// so delegate it to `Ord` which is already producing -1/0/+1
26112610
// exactly like we need and can be the place to deal with the complexity.
2612-
self.cmp(&0) as _
2611+
2612+
// FIXME(const-hack): replace with cmp
2613+
if self < 0 { -1 }
2614+
else if self == 0 { 0 }
2615+
else { 1 }
26132616
}
26142617

26152618
/// Returns `true` if `self` is positive and `false` if the number is zero or

0 commit comments

Comments
 (0)