From e6db701d5b09c169297aaaf2d5d53f64bcb4676e Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Sun, 9 Nov 2014 16:59:28 +1100 Subject: [PATCH] Deprecate Signed method wrappers --- src/libcore/num/mod.rs | 26 +++++-------------- src/librand/distributions/mod.rs | 3 +-- src/libtest/stats.rs | 8 +++--- src/libtime/lib.rs | 5 ++-- .../trait-inheritance-self-in-supertype.rs | 6 ++--- src/test/run-pass/utf8_idents.rs | 4 +-- 6 files changed, 16 insertions(+), 36 deletions(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 86ac4ea79ced..61fabae4b8b0 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(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(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(value: T) -> T { value.abs() } +#[deprecated = "Use `Signed::abs_sub`"] +pub fn abs_sub(x: T, y: T) -> T { x.abs_sub(y) } diff --git a/src/librand/distributions/mod.rs b/src/librand/distributions/mod.rs index 660603198915..7d454e49006b 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( 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 8c184ccbe43a..ff274c874a85 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(x: T, y: T) -> Ordering { // arbitrarily decide that NaNs are larger than everything. @@ -166,7 +165,6 @@ impl Summary { } impl<'a, T: FloatMath + FromPrimitive> Stats 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 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 for &'a [T] { fn median_abs_dev(self) -> T { let med = self.median(); - let abs_devs: Vec = self.iter().map(|&v| num::abs(med - v)).collect(); + let abs_devs: Vec = 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 bbe6002717c8..acd81d4566b9 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 63ac921e2a52..c7e206cb474b 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 { @@ -29,7 +27,7 @@ impl FuzzyEq 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 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 f6c4776a11cc..68964fa49571 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); }