Skip to content

Commit

Permalink
core: add abs to num.
Browse files Browse the repository at this point in the history
  • Loading branch information
graydon committed Feb 13, 2013
1 parent 389125a commit 73280b0
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/libcore/num/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ pub trait One {
static pure fn one() -> Self;
}

pub pure fn abs<T: cmp::Ord Num Zero>(v: T) -> T {
if v < Zero::zero() { v.neg() } else { v }
}

pub trait Round {
pure fn round(&self, mode: RoundMode) -> Self;

Expand Down

0 comments on commit 73280b0

Please sign in to comment.