Make i*::signum a const fn.
This uses a well-known branchless implementation of `signum`. Its `const`-ness is unstable and requires `#![feature(const_int_sign)]`.
This commit is contained in:
@@ -1993,13 +1993,10 @@ assert_eq!((-10", stringify!($SelfT), ").signum(), -1);",
|
|||||||
$EndFeature, "
|
$EndFeature, "
|
||||||
```"),
|
```"),
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[rustc_const_unstable(feature = "const_int_sign")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn signum(self) -> Self {
|
pub const fn signum(self) -> Self {
|
||||||
match self {
|
(self > 0) as Self - (self < 0) as Self
|
||||||
n if n > 0 => 1,
|
|
||||||
0 => 0,
|
|
||||||
_ => -1,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user