hack signum as well
This commit is contained in:
parent
8cda8df578
commit
d88f979437
@ -2603,13 +2603,16 @@ pub const fn abs_diff(self, other: Self) -> $UnsignedT {
|
||||
#[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
|
||||
|
Loading…
Reference in New Issue
Block a user