diff options
| author | Graydon Hoare <graydon@mozilla.com> | 2013-01-15 17:30:16 -0800 |
|---|---|---|
| committer | Graydon Hoare <graydon@mozilla.com> | 2013-02-13 11:46:25 -0800 |
| commit | 73280b0472afdcf4df7eb1a80a7ac0b74a791ca9 (patch) | |
| tree | 40a485ee5a9219e19c90a83b43b4212b8f23fabe | |
| parent | 389125aeb83eb1571ff1ec4e5e140b1ac2109341 (diff) | |
| download | rust-73280b0472afdcf4df7eb1a80a7ac0b74a791ca9.tar.gz rust-73280b0472afdcf4df7eb1a80a7ac0b74a791ca9.zip | |
core: add abs to num.
| -rw-r--r-- | src/libcore/num/num.rs | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/libcore/num/num.rs b/src/libcore/num/num.rs index eb722b441c7..9ba53defd6e 100644 --- a/src/libcore/num/num.rs +++ b/src/libcore/num/num.rs @@ -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; |
