about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBrendan Zabarauskas <bjzaba@yahoo.com.au>2014-11-09 16:59:28 +1100
committerBrendan Zabarauskas <bjzaba@yahoo.com.au>2014-11-13 02:02:43 +1100
commite6db701d5b09c169297aaaf2d5d53f64bcb4676e (patch)
tree2e43cc404663158bd2e4fef75e0c53c1183776ff
parent8666812dce7e219501642d4aabfd89e6b986834f (diff)
downloadrust-e6db701d5b09c169297aaaf2d5d53f64bcb4676e.tar.gz
rust-e6db701d5b09c169297aaaf2d5d53f64bcb4676e.zip
Deprecate Signed method wrappers
-rw-r--r--src/libcore/num/mod.rs26
-rw-r--r--src/librand/distributions/mod.rs3
-rw-r--r--src/libtest/stats.rs8
-rw-r--r--src/libtime/lib.rs5
-rw-r--r--src/test/run-pass/trait-inheritance-self-in-supertype.rs6
-rw-r--r--src/test/run-pass/utf8_idents.rs4
6 files changed, 16 insertions, 36 deletions
diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs
index 86ac4ea79ce..61fabae4b8b 100644
--- a/src/libcore/num/mod.rs
+++ b/src/libcore/num/mod.rs
@@ -271,25 +271,6 @@ signed_float_impl!(f32, f32::NAN, f32::INFINITY, f32::NEG_INFINITY,
 signed_float_impl!(f64, f64::NAN, f64::INFINITY, f64::NEG_INFINITY,
                    intrinsics::fabsf64, intrinsics::copysignf64, fdim)
 
-/// Computes the absolute value.
-///
-/// 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`.
-#[inline(always)]
-pub fn abs<T: Signed>(value: T) -> T {
-    value.abs()
-}
-
-/// The positive difference of two numbers.
-///
-/// Returns zero if `x` is less than or equal to `y`, otherwise the difference
-/// between `x` and `y` is returned.
-#[inline(always)]
-pub fn abs_sub<T: Signed>(x: T, y: T) -> T {
-    x.abs_sub(y)
-}
-
 /// Returns the sign of the number.
 ///
 /// For `f32` and `f64`:
@@ -1560,3 +1541,10 @@ pub trait Float: Signed + Primitive {
     /// Convert degrees to radians.
     fn to_radians(self) -> Self;
 }
+
+// DEPRECATED
+
+#[deprecated = "Use `Signed::abs`"]
+pub fn abs<T: Signed>(value: T) -> T { value.abs() }
+#[deprecated = "Use `Signed::abs_sub`"]
+pub fn abs_sub<T: Signed>(x: T, y: T) -> T { x.abs_sub(y) }
diff --git a/src/librand/distributions/mod.rs b/src/librand/distributions/mod.rs
index 66060319891..7d454e49006 100644
--- a/src/librand/distributions/mod.rs
+++ b/src/librand/distributions/mod.rs
@@ -23,7 +23,6 @@ that do not need to record state.
 #![experimental]
 
 use core::prelude::*;
-use core::num;
 
 use {Rng, Rand};
 
@@ -243,7 +242,7 @@ fn ziggurat<R:Rng>(
         let u = if symmetric {2.0 * f - 1.0} else {f};
         let x = u * x_tab[i];
 
-        let test_x = if symmetric {num::abs(x)} else {x};
+        let test_x = if symmetric { x.abs() } else {x};
 
         // algebraically equivalent to |u| < x_tab[i+1]/x_tab[i] (or u < x_tab[i+1]/x_tab[i])
         if test_x < x_tab[i + 1] {
diff --git a/src/libtest/stats.rs b/src/libtest/stats.rs
index 8c184ccbe43..ff274c874a8 100644
--- a/src/libtest/stats.rs
+++ b/src/libtest/stats.rs
@@ -17,7 +17,6 @@ use std::hash::Hash;
 use std::io;
 use std::mem;
 use std::num::Zero;
-use std::num;
 
 fn local_cmp<T:Float>(x: T, y: T) -> Ordering {
     // arbitrarily decide that NaNs are larger than everything.
@@ -166,7 +165,6 @@ impl<T: FloatMath + FromPrimitive> Summary<T> {
 }
 
 impl<'a, T: FloatMath + FromPrimitive> Stats<T> for &'a [T] {
-
     // FIXME #11059 handle NaN, inf and overflow
     fn sum(self) -> T {
         let mut partials = vec![];
@@ -176,8 +174,8 @@ impl<'a, T: FloatMath + FromPrimitive> Stats<T> for &'a [T] {
             // This inner loop applies `hi`/`lo` summation to each
             // partial so that the list of partial sums remains exact.
             for i in range(0, partials.len()) {
-                let mut y = partials[i];
-                if num::abs(x) < num::abs(y) {
+                let mut y: T = partials[i];
+                if x.abs() < y.abs() {
                     mem::swap(&mut x, &mut y);
                 }
                 // Rounded `x+y` is stored in `hi` with round-off stored in
@@ -249,7 +247,7 @@ impl<'a, T: FloatMath + FromPrimitive> Stats<T> for &'a [T] {
 
     fn median_abs_dev(self) -> T {
         let med = self.median();
-        let abs_devs: Vec<T> = self.iter().map(|&v| num::abs(med - v)).collect();
+        let abs_devs: Vec<T> = self.iter().map(|&v| (med - v).abs()).collect();
         // This constant is derived by smarter statistics brains than me, but it is
         // consistent with how R and other packages treat the MAD.
         let number = FromPrimitive::from_f64(1.4826).unwrap();
diff --git a/src/libtime/lib.rs b/src/libtime/lib.rs
index bbe6002717c..acd81d4566b 100644
--- a/src/libtime/lib.rs
+++ b/src/libtime/lib.rs
@@ -30,7 +30,6 @@ extern crate libc;
 use std::fmt::Show;
 use std::fmt;
 use std::io::BufReader;
-use std::num;
 use std::string::String;
 use std::time::Duration;
 
@@ -757,7 +756,7 @@ impl<'a> fmt::Show for TmFmt<'a> {
               'Z' => if tm.tm_gmtoff == 0_i32 { "GMT"} else { "" }, // FIXME (#2350): support locale
               'z' => {
                 let sign = if tm.tm_gmtoff > 0_i32 { '+' } else { '-' };
-                let mut m = num::abs(tm.tm_gmtoff) / 60_i32;
+                let mut m = tm.tm_gmtoff.abs() / 60_i32;
                 let h = m / 60_i32;
                 m -= h * 60_i32;
                 return write!(fmt, "{}{:02d}{:02d}", sign, h, m);
@@ -799,7 +798,7 @@ impl<'a> fmt::Show for TmFmt<'a> {
                         format: FmtStr("%Y-%m-%dT%H:%M:%S"),
                     };
                     let sign = if self.tm.tm_gmtoff > 0_i32 { '+' } else { '-' };
-                    let mut m = num::abs(self.tm.tm_gmtoff) / 60_i32;
+                    let mut m = self.tm.tm_gmtoff.abs() / 60_i32;
                     let h = m / 60_i32;
                     m -= h * 60_i32;
                     write!(fmt, "{}{}{:02d}:{:02d}", s, sign, h as int, m as int)
diff --git a/src/test/run-pass/trait-inheritance-self-in-supertype.rs b/src/test/run-pass/trait-inheritance-self-in-supertype.rs
index 63ac921e2a5..c7e206cb474 100644
--- a/src/test/run-pass/trait-inheritance-self-in-supertype.rs
+++ b/src/test/run-pass/trait-inheritance-self-in-supertype.rs
@@ -10,8 +10,6 @@
 
 // Test for issue #4183: use of Self in supertraits.
 
-use std::num;
-
 pub static FUZZY_EPSILON: f64 = 0.1;
 
 pub trait FuzzyEq<Eps> {
@@ -29,7 +27,7 @@ impl FuzzyEq<f32> for f32 {
     }
 
     fn fuzzy_eq_eps(&self, other: &f32, epsilon: &f32) -> bool {
-        num::abs(*self - *other) < *epsilon
+        (*self - *other).abs() < *epsilon
     }
 }
 
@@ -43,7 +41,7 @@ impl FuzzyEq<f64> for f64 {
     }
 
     fn fuzzy_eq_eps(&self, other: &f64, epsilon: &f64) -> bool {
-        num::abs(*self - *other) < *epsilon
+        (*self - *other).abs() < *epsilon
     }
 }
 
diff --git a/src/test/run-pass/utf8_idents.rs b/src/test/run-pass/utf8_idents.rs
index f6c4776a11c..68964fa4957 100644
--- a/src/test/run-pass/utf8_idents.rs
+++ b/src/test/run-pass/utf8_idents.rs
@@ -13,13 +13,11 @@
 
 #![feature(non_ascii_idents)]
 
-use std::num;
-
 pub fn main() {
     let ε = 0.00001f64;
     let Π = 3.14f64;
     let लंच = Π * Π + 1.54;
-    assert!(num::abs((लंच - 1.54) - (Π * Π)) < ε);
+    assert!(((लंच - 1.54) - (Π * Π)).abs() < ε);
     assert_eq!(საჭმელად_გემრიელი_სადილი(), 0);
 }