Skip to content

Commit 73280b0

Browse files
committed
core: add abs to num.
1 parent 389125a commit 73280b0

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/libcore/num/num.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ pub trait One {
3939
static pure fn one() -> Self;
4040
}
4141

42+
pub pure fn abs<T: cmp::Ord Num Zero>(v: T) -> T {
43+
if v < Zero::zero() { v.neg() } else { v }
44+
}
45+
4246
pub trait Round {
4347
pure fn round(&self, mode: RoundMode) -> Self;
4448

0 commit comments

Comments
 (0)