side-step potentially panic'ing negate in fn abs.

This commit is contained in:
Felix S. Klock II 2015-04-15 12:27:23 +02:00
parent c34fa8b2c5
commit e9f892acc4

View File

@ -1321,7 +1321,11 @@ pub fn pow(self, mut exp: u32) -> $T {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn abs(self) -> $T {
if self.is_negative() { -self } else { self }
if self.is_negative() {
self.wrapping_neg()
} else {
self
}
}
/// Returns a number representing sign of `self`.