diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index d14bcb36944..86ac4ea79ce 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -162,13 +162,13 @@ pub trait Signed: Num + Neg { /// For `f32` and `f64`, `NaN` will be returned if the number is `NaN`. /// /// For signed integers, `::MIN` will be returned if the number is `::MIN`. - fn abs(&self) -> Self; + fn abs(self) -> Self; /// The positive difference of two numbers. /// /// Returns `zero` if the number is less than or equal to `other`, otherwise the difference /// between `self` and `other` is returned. - fn abs_sub(&self, other: &Self) -> Self; + fn abs_sub(self, other: Self) -> Self; /// Returns the sign of the number. /// @@ -183,31 +183,31 @@ pub trait Signed: Num + Neg { /// * `0` if the number is zero /// * `1` if the number is positive /// * `-1` if the number is negative - fn signum(&self) -> Self; + fn signum(self) -> Self; /// Returns true if the number is positive and false if the number is zero or negative. - fn is_positive(&self) -> bool; + fn is_positive(self) -> bool; /// Returns true if the number is negative and false if the number is zero or positive. - fn is_negative(&self) -> bool; + fn is_negative(self) -> bool; } macro_rules! signed_impl( - ($($t:ty)*) => ($( - impl Signed for $t { + ($($T:ty)*) => ($( + impl Signed for $T { #[inline] - fn abs(&self) -> $t { - if self.is_negative() { -*self } else { *self } + fn abs(self) -> $T { + if self.is_negative() { -self } else { self } } #[inline] - fn abs_sub(&self, other: &$t) -> $t { - if *self <= *other { 0 } else { *self - *other } + fn abs_sub(self, other: $T) -> $T { + if self <= other { 0 } else { self - other } } #[inline] - fn signum(&self) -> $t { - match *self { + fn signum(self) -> $T { + match self { n if n > 0 => 1, 0 => 0, _ => -1, @@ -215,10 +215,10 @@ macro_rules! signed_impl( } #[inline] - fn is_positive(&self) -> bool { *self > 0 } + fn is_positive(self) -> bool { self > 0 } #[inline] - fn is_negative(&self) -> bool { *self < 0 } + fn is_negative(self) -> bool { self < 0 } } )*) ) @@ -226,21 +226,21 @@ macro_rules! signed_impl( signed_impl!(int i8 i16 i32 i64) macro_rules! signed_float_impl( - ($t:ty, $nan:expr, $inf:expr, $neg_inf:expr, $fabs:path, $fcopysign:path, $fdim:ident) => { - impl Signed for $t { + ($T:ty, $nan:expr, $inf:expr, $neg_inf:expr, $fabs:path, $fcopysign:path, $fdim:ident) => { + impl Signed for $T { /// Computes the absolute value. Returns `NAN` if the number is `NAN`. #[inline] - fn abs(&self) -> $t { - unsafe { $fabs(*self) } + fn abs(self) -> $T { + unsafe { $fabs(self) } } /// The positive difference of two numbers. Returns `0.0` if the number is /// less than or equal to `other`, otherwise the difference between`self` /// and `other` is returned. #[inline] - fn abs_sub(&self, other: &$t) -> $t { - extern { fn $fdim(a: $t, b: $t) -> $t; } - unsafe { $fdim(*self, *other) } + fn abs_sub(self, other: $T) -> $T { + extern { fn $fdim(a: $T, b: $T) -> $T; } + unsafe { $fdim(self, other) } } /// # Returns @@ -249,19 +249,19 @@ macro_rules! signed_float_impl( /// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` /// - `NAN` if the number is NaN #[inline] - fn signum(&self) -> $t { + fn signum(self) -> $T { if self != self { $nan } else { - unsafe { $fcopysign(1.0, *self) } + unsafe { $fcopysign(1.0, self) } } } /// Returns `true` if the number is positive, including `+0.0` and `INFINITY` #[inline] - fn is_positive(&self) -> bool { *self > 0.0 || (1.0 / *self) == $inf } + fn is_positive(self) -> bool { self > 0.0 || (1.0 / self) == $inf } /// Returns `true` if the number is negative, including `-0.0` and `NEG_INFINITY` #[inline] - fn is_negative(&self) -> bool { *self < 0.0 || (1.0 / *self) == $neg_inf } + fn is_negative(self) -> bool { self < 0.0 || (1.0 / self) == $neg_inf } } } ) @@ -287,7 +287,7 @@ pub fn abs(value: T) -> T { /// between `x` and `y` is returned. #[inline(always)] pub fn abs_sub(x: T, y: T) -> T { - x.abs_sub(&y) + x.abs_sub(y) } /// Returns the sign of the number. diff --git a/src/libcoretest/num/int_macros.rs b/src/libcoretest/num/int_macros.rs index f74f503383b..1b3dd8ffa5e 100644 --- a/src/libcoretest/num/int_macros.rs +++ b/src/libcoretest/num/int_macros.rs @@ -39,10 +39,10 @@ mod tests { #[test] fn test_abs_sub() { - assert!((-1 as $T).abs_sub(&(1 as $T)) == 0 as $T); - assert!((1 as $T).abs_sub(&(1 as $T)) == 0 as $T); - assert!((1 as $T).abs_sub(&(0 as $T)) == 1 as $T); - assert!((1 as $T).abs_sub(&(-1 as $T)) == 2 as $T); + assert!((-1 as $T).abs_sub(1 as $T) == 0 as $T); + assert!((1 as $T).abs_sub(1 as $T) == 0 as $T); + assert!((1 as $T).abs_sub(0 as $T) == 1 as $T); + assert!((1 as $T).abs_sub(-1 as $T) == 2 as $T); } #[test] diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs index 63c3956ef24..175b1612b7e 100644 --- a/src/libstd/num/f32.rs +++ b/src/libstd/num/f32.rs @@ -593,20 +593,20 @@ mod tests { #[test] fn test_abs_sub() { - assert_eq!((-1f32).abs_sub(&1f32), 0f32); - assert_eq!(1f32.abs_sub(&1f32), 0f32); - assert_eq!(1f32.abs_sub(&0f32), 1f32); - assert_eq!(1f32.abs_sub(&-1f32), 2f32); - assert_eq!(NEG_INFINITY.abs_sub(&0f32), 0f32); - assert_eq!(INFINITY.abs_sub(&1f32), INFINITY); - assert_eq!(0f32.abs_sub(&NEG_INFINITY), INFINITY); - assert_eq!(0f32.abs_sub(&INFINITY), 0f32); + assert_eq!((-1f32).abs_sub(1f32), 0f32); + assert_eq!(1f32.abs_sub(1f32), 0f32); + assert_eq!(1f32.abs_sub(0f32), 1f32); + assert_eq!(1f32.abs_sub(-1f32), 2f32); + assert_eq!(NEG_INFINITY.abs_sub(0f32), 0f32); + assert_eq!(INFINITY.abs_sub(1f32), INFINITY); + assert_eq!(0f32.abs_sub(NEG_INFINITY), INFINITY); + assert_eq!(0f32.abs_sub(INFINITY), 0f32); } #[test] fn test_abs_sub_nowin() { - assert!(NAN.abs_sub(&-1f32).is_nan()); - assert!(1f32.abs_sub(&NAN).is_nan()); + assert!(NAN.abs_sub(-1f32).is_nan()); + assert!(1f32.abs_sub(NAN).is_nan()); } #[test] diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs index 6e8e92eb91d..eb8e8db798c 100644 --- a/src/libstd/num/f64.rs +++ b/src/libstd/num/f64.rs @@ -591,20 +591,20 @@ mod tests { #[test] fn test_abs_sub() { - assert_eq!((-1f64).abs_sub(&1f64), 0f64); - assert_eq!(1f64.abs_sub(&1f64), 0f64); - assert_eq!(1f64.abs_sub(&0f64), 1f64); - assert_eq!(1f64.abs_sub(&-1f64), 2f64); - assert_eq!(NEG_INFINITY.abs_sub(&0f64), 0f64); - assert_eq!(INFINITY.abs_sub(&1f64), INFINITY); - assert_eq!(0f64.abs_sub(&NEG_INFINITY), INFINITY); - assert_eq!(0f64.abs_sub(&INFINITY), 0f64); + assert_eq!((-1f64).abs_sub(1f64), 0f64); + assert_eq!(1f64.abs_sub(1f64), 0f64); + assert_eq!(1f64.abs_sub(0f64), 1f64); + assert_eq!(1f64.abs_sub(-1f64), 2f64); + assert_eq!(NEG_INFINITY.abs_sub(0f64), 0f64); + assert_eq!(INFINITY.abs_sub(1f64), INFINITY); + assert_eq!(0f64.abs_sub(NEG_INFINITY), INFINITY); + assert_eq!(0f64.abs_sub(INFINITY), 0f64); } #[test] fn test_abs_sub_nowin() { - assert!(NAN.abs_sub(&-1f64).is_nan()); - assert!(1f64.abs_sub(&NAN).is_nan()); + assert!(NAN.abs_sub(-1f64).is_nan()); + assert!(1f64.abs_sub(NAN).is_nan()); } #[test]