From 389125aeb83eb1571ff1ec4e5e140b1ac2109341 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Tue, 15 Jan 2013 17:30:01 -0800 Subject: [PATCH] core: add min and max to cmp, re-export various places. --- src/libcore/cmp.rs | 9 +++++++++ src/libcore/num/f64.rs | 1 + src/libcore/num/int-template.rs | 6 +----- 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(v1: &T, v2: &T) -> bool { (*v1).gt(v2) } +#[inline(always)] +pub pure fn min(v1: T, v2: T) -> T { + if v1 < v2 { v1 } else { v2 } +} + +#[inline(always)] +pub pure fn max(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); @@ -31,11 +32,6 @@ pub const bytes : uint = (inst::bits / 8); 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)] 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,17 +27,14 @@ use u8; use u16; use u32; +pub use cmp::{min, max}; + pub const bits : uint = inst::bits; pub const bytes : uint = (inst::bits / 8); 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)]