Skip to content

Commit

Permalink
side-step potentially panic'ing negate in fn abs.
Browse files Browse the repository at this point in the history
  • Loading branch information
pnkfelix committed Apr 17, 2015
1 parent c34fa8b commit e9f892a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/libcore/num/mod.rs
Expand Up @@ -1321,7 +1321,11 @@ macro_rules! int_impl {
#[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`.
Expand Down

0 comments on commit e9f892a

Please sign in to comment.