Use cond! macro where appropriate
This commit is contained in:
parent
8badea49b0
commit
a10974da2d
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
pub mod general_category {
|
||||
|
||||
#[cfg(stage0)]
|
||||
fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
|
||||
use cmp::{Equal, Less, Greater};
|
||||
use vec::bsearch;
|
||||
@ -25,6 +26,18 @@ pub mod general_category {
|
||||
}) != None
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
|
||||
use cmp::{Equal, Less, Greater};
|
||||
use vec::bsearch;
|
||||
use option::None;
|
||||
(do bsearch(r) |&(lo,hi)| { cond!(
|
||||
(lo <= c && c <= hi) { Equal }
|
||||
(hi < c) { Less }
|
||||
_ { Greater }
|
||||
)}) != None
|
||||
}
|
||||
|
||||
|
||||
static Cc_table : &'static [(char,char)] = &[
|
||||
('\x00', '\x1f'), ('\x7f', '\x9f')
|
||||
@ -1449,8 +1462,7 @@ pub mod general_category {
|
||||
}
|
||||
|
||||
pub mod derived_property {
|
||||
|
||||
|
||||
#[cfg(stage0)]
|
||||
fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
|
||||
use cmp::{Equal, Less, Greater};
|
||||
use vec::bsearch;
|
||||
@ -1462,6 +1474,18 @@ pub mod derived_property {
|
||||
}) != None
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
|
||||
use cmp::{Equal, Less, Greater};
|
||||
use vec::bsearch;
|
||||
use option::None;
|
||||
(do bsearch(r) |&(lo,hi)| { cond!(
|
||||
(lo <= c && c <= hi) { Equal }
|
||||
(hi < c) { Less }
|
||||
_ { Greater }
|
||||
)}) != None
|
||||
}
|
||||
|
||||
|
||||
static Alphabetic_table : &'static [(char,char)] = &[
|
||||
('\x41', '\x5a'), ('\x61', '\x7a'),
|
||||
|
Loading…
Reference in New Issue
Block a user