Deprecate Signed method wrappers

This commit is contained in:
Brendan Zabarauskas 2014-11-09 16:59:28 +11:00
parent 8666812dce
commit e6db701d5b
6 changed files with 16 additions and 36 deletions

View File

@ -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) }

View File

@ -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] {

View File

@ -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();

View File

@ -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)

View File

@ -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
}
}

View File

@ -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);
}