diff options
| author | Deadbeef <ent3rm4n@gmail.com> | 2023-04-16 07:04:17 +0000 |
|---|---|---|
| committer | Deadbeef <ent3rm4n@gmail.com> | 2023-04-16 07:04:17 +0000 |
| commit | d88f979437299dfda0f5214ec14e809a10e10ff0 (patch) | |
| tree | 689c08282a8528dcbe4767be74a72e6fd7420e24 | |
| parent | 8cda8df578d77ee989de9d4a44db6991d0b06cfd (diff) | |
| download | rust-d88f979437299dfda0f5214ec14e809a10e10ff0.tar.gz rust-d88f979437299dfda0f5214ec14e809a10e10ff0.zip | |
hack signum as well
| -rw-r--r-- | library/core/src/num/int_macros.rs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index aec15212d7f..d645e8dcbfd 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -2603,13 +2603,16 @@ macro_rules! int_impl { #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline(always)] - #[rustc_allow_const_fn_unstable(const_cmp)] pub const fn signum(self) -> Self { // Picking the right way to phrase this is complicated // (<https://graphics.stanford.edu/~seander/bithacks.html#CopyIntegerSign>) // so delegate it to `Ord` which is already producing -1/0/+1 // exactly like we need and can be the place to deal with the complexity. - self.cmp(&0) as _ + + // FIXME(const-hack): replace with cmp + if self < 0 { -1 } + else if self == 0 { 0 } + else { 1 } } /// Returns `true` if `self` is positive and `false` if the number is zero or |
