diff options
| author | Graydon Hoare <graydon@mozilla.com> | 2013-01-15 17:30:01 -0800 |
|---|---|---|
| committer | Graydon Hoare <graydon@mozilla.com> | 2013-02-13 11:46:25 -0800 |
| commit | 389125aeb83eb1571ff1ec4e5e140b1ac2109341 (patch) | |
| tree | e4ee3e2e634ab805c502be38534da08c28baa105 | |
| parent | d06e6e758aff5ec19f165519447e620f98b00c03 (diff) | |
| download | rust-389125aeb83eb1571ff1ec4e5e140b1ac2109341.tar.gz rust-389125aeb83eb1571ff1ec4e5e140b1ac2109341.zip | |
core: add min and max to cmp, re-export various places.
| -rw-r--r-- | src/libcore/cmp.rs | 9 | ||||
| -rw-r--r-- | src/libcore/num/f64.rs | 1 | ||||
| -rw-r--r-- | src/libcore/num/int-template.rs | 6 | ||||
| -rw-r--r-- | src/libcore/num/uint-template.rs | 7 |
4 files changed, 13 insertions, 10 deletions
diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index e1ec8c7737c..7cd4d4c9bc3 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -85,3 +85,12 @@ pub pure fn gt<T: Ord>(v1: &T, v2: &T) -> bool { (*v1).gt(v2) } +#[inline(always)] +pub pure fn min<T: Ord>(v1: T, v2: T) -> T { + if v1 < v2 { v1 } else { v2 } +} + +#[inline(always)] +pub pure fn max<T: Ord>(v1: T, v2: T) -> T { + if v1 > v2 { v1 } else { v2 } +} diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs index 7cde2102653..75f68fdafc7 100644 --- a/src/libcore/num/f64.rs +++ b/src/libcore/num/f64.rs @@ -21,6 +21,7 @@ use to_str; use from_str; pub use cmath::c_double_targ_consts::*; +pub use cmp::{min, max}; macro_rules! delegate( ( diff --git a/src/libcore/num/int-template.rs b/src/libcore/num/int-template.rs index b616a08246b..4c22a8001e9 100644 --- a/src/libcore/num/int-template.rs +++ b/src/libcore/num/int-template.rs @@ -24,6 +24,7 @@ use vec; use i8; use i16; use i32; +pub use cmp::{min, max}; pub const bits : uint = inst::bits; pub const bytes : uint = (inst::bits / 8); @@ -32,11 +33,6 @@ pub const min_value: T = (-1 as T) << (bits - 1); pub const max_value: T = min_value - 1 as T; #[inline(always)] -pub pure fn min(x: T, y: T) -> T { if x < y { x } else { y } } -#[inline(always)] -pub pure fn max(x: T, y: T) -> T { if x > y { x } else { y } } - -#[inline(always)] pub pure fn add(x: T, y: T) -> T { x + y } #[inline(always)] pub pure fn sub(x: T, y: T) -> T { x - y } diff --git a/src/libcore/num/uint-template.rs b/src/libcore/num/uint-template.rs index 0a219660fb9..4a3c5715201 100644 --- a/src/libcore/num/uint-template.rs +++ b/src/libcore/num/uint-template.rs @@ -27,6 +27,8 @@ use u8; use u16; use u32; +pub use cmp::{min, max}; + pub const bits : uint = inst::bits; pub const bytes : uint = (inst::bits / 8); @@ -34,11 +36,6 @@ pub const min_value: T = 0 as T; pub const max_value: T = 0 as T - 1 as T; #[inline(always)] -pub pure fn min(x: T, y: T) -> T { if x < y { x } else { y } } -#[inline(always)] -pub pure fn max(x: T, y: T) -> T { if x > y { x } else { y } } - -#[inline(always)] pub pure fn add(x: T, y: T) -> T { x + y } #[inline(always)] pub pure fn sub(x: T, y: T) -> T { x - y } |
