Move abs_sub to FloatMath

This removes the need for libcore to depend on libm. `abs_sub` is not as useful for integers.
This commit is contained in:
Brendan Zabarauskas
2014-11-09 17:24:14 +11:00
parent e6db701d5b
commit 9fe94bd995
5 changed files with 23 additions and 31 deletions

View File

@@ -164,12 +164,6 @@ pub trait Signed: Num + Neg<Self> {
/// For signed integers, `::MIN` will be returned if the number is `::MIN`.
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;
/// Returns the sign of the number.
///
/// For `f32` and `f64`:
@@ -200,11 +194,6 @@ macro_rules! signed_impl(
if self.is_negative() { -self } else { self }
}
#[inline]
fn abs_sub(self, other: $T) -> $T {
if self <= other { 0 } else { self - other }
}
#[inline]
fn signum(self) -> $T {
match self {
@@ -234,15 +223,6 @@ macro_rules! signed_float_impl(
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) }
}
/// # Returns
///
/// - `1.0` if the number is positive, `+0.0` or `INFINITY`
@@ -1546,5 +1526,3 @@ pub trait Float: Signed + Primitive {
#[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) }