]> git.lizzy.rs Git - rust.git/blobdiff - src/libcore/num/mod.rs
Auto merge of #61635 - ecstatic-morse:const-signum, r=oli-obk
[rust.git] / src / libcore / num / mod.rs
index dd7090623f5b3bdd6628ebaf44874cae95560072..304b2fc9ebb06e56e61c600d9ad9b58091b3c9c3 100644 (file)
@@ -1993,13 +1993,10 @@ pub fn abs(self) -> Self {
 $EndFeature, "
 ```"),
             #[stable(feature = "rust1", since = "1.0.0")]
+            #[rustc_const_unstable(feature = "const_int_sign")]
             #[inline]
-            pub fn signum(self) -> Self {
-                match self {
-                    n if n > 0 =>  1,
-                    0          =>  0,
-                    _          => -1,
-                }
+            pub const fn signum(self) -> Self {
+                (self > 0) as Self - (self < 0) as Self
             }
         }