diff options
| author | Brendan Zabarauskas <bjzaba@yahoo.com.au> | 2013-05-18 15:02:58 +1000 |
|---|---|---|
| committer | Brendan Zabarauskas <bjzaba@yahoo.com.au> | 2013-05-18 17:29:07 +1000 |
| commit | a10974da2db2e483f21e337f0c9a8a1e1c4c81ed (patch) | |
| tree | 8f8bf9bc9ae05e9970ffeb2cd357257ac341e803 /src/libcore/num | |
| parent | 8badea49b0291d5ea0979a8edfb1ebb4f01b043d (diff) | |
| download | rust-a10974da2db2e483f21e337f0c9a8a1e1c4c81ed.tar.gz rust-a10974da2db2e483f21e337f0c9a8a1e1c4c81ed.zip | |
Use cond! macro where appropriate
Diffstat (limited to 'src/libcore/num')
| -rw-r--r-- | src/libcore/num/f32.rs | 16 | ||||
| -rw-r--r-- | src/libcore/num/f64.rs | 16 | ||||
| -rw-r--r-- | src/libcore/num/int-template.rs | 12 | ||||
| -rw-r--r-- | src/libcore/num/uint-template.rs | 12 |
4 files changed, 52 insertions, 4 deletions
diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs index 4a3ec3528f2..d580f7aa26c 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -248,8 +248,7 @@ impl Orderable for f32 { if self.is_NaN() || other.is_NaN() { Float::NaN() } else { fmax(*self, *other) } } - /// Returns the number constrained within the range `mn <= self <= mx`. - /// If any of the numbers are `NaN` then `NaN` is returned. + #[cfg(stage0)] #[inline(always)] fn clamp(&self, mn: &f32, mx: &f32) -> f32 { if self.is_NaN() { *self } @@ -257,6 +256,19 @@ impl Orderable for f32 { else if !(*self >= *mn) { *mn } else { *self } } + + /// Returns the number constrained within the range `mn <= self <= mx`. + /// If any of the numbers are `NaN` then `NaN` is returned. + #[cfg(not(stage0))] + #[inline(always)] + fn clamp(&self, mn: &f32, mx: &f32) -> f32 { + cond!( + (self.is_NaN()) { *self } + (!(*self <= *mx)) { *mx } + (!(*self >= *mn)) { *mn } + _ { *self } + ) + } } impl Zero for f32 { diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs index e370f43a003..d140df30c42 100644 --- a/src/libcore/num/f64.rs +++ b/src/libcore/num/f64.rs @@ -270,8 +270,7 @@ impl Orderable for f64 { if self.is_NaN() || other.is_NaN() { Float::NaN() } else { fmax(*self, *other) } } - /// Returns the number constrained within the range `mn <= self <= mx`. - /// If any of the numbers are `NaN` then `NaN` is returned. + #[cfg(stage0)] #[inline(always)] fn clamp(&self, mn: &f64, mx: &f64) -> f64 { if self.is_NaN() { *self } @@ -279,6 +278,19 @@ impl Orderable for f64 { else if !(*self >= *mn) { *mn } else { *self } } + + /// Returns the number constrained within the range `mn <= self <= mx`. + /// If any of the numbers are `NaN` then `NaN` is returned. + #[cfg(not(stage0))] + #[inline(always)] + fn clamp(&self, mn: &f64, mx: &f64) -> f64 { + cond!( + (self.is_NaN()) { *self } + (!(*self <= *mx)) { *mx } + (!(*self >= *mn)) { *mn } + _ { *self } + ) + } } impl Zero for f64 { diff --git a/src/libcore/num/int-template.rs b/src/libcore/num/int-template.rs index 348f72f9f0a..d0e6174ec63 100644 --- a/src/libcore/num/int-template.rs +++ b/src/libcore/num/int-template.rs @@ -187,11 +187,23 @@ impl Orderable for T { if *self > *other { *self } else { *other } } + #[cfg(stage0)] #[inline(always)] fn clamp(&self, mn: &T, mx: &T) -> T { if *self > *mx { *mx } else if *self < *mn { *mn } else { *self } } + + /// Returns the number constrained within the range `mn <= self <= mx`. + #[cfg(not(stage0))] + #[inline(always)] + fn clamp(&self, mn: &T, mx: &T) -> T { + cond!( + (*self > *mx) { *mx } + (*self < *mn) { *mn } + _ { *self } + ) + } } impl Zero for T { diff --git a/src/libcore/num/uint-template.rs b/src/libcore/num/uint-template.rs index da0815c264b..f3e14094505 100644 --- a/src/libcore/num/uint-template.rs +++ b/src/libcore/num/uint-template.rs @@ -153,11 +153,23 @@ impl Orderable for T { if *self > *other { *self } else { *other } } + #[cfg(stage0)] #[inline(always)] fn clamp(&self, mn: &T, mx: &T) -> T { if *self > *mx { *mx } else if *self < *mn { *mn } else { *self } } + + /// Returns the number constrained within the range `mn <= self <= mx`. + #[cfg(not(stage0))] + #[inline(always)] + fn clamp(&self, mn: &T, mx: &T) -> T { + cond!( + (*self > *mx) { *mx } + (*self < *mn) { *mn } + _ { *self } + ) + } } impl Zero for T { |
