1
Fork 0

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

@ -21,7 +21,7 @@ use option::Option;
#[cfg(test)] use fmt::Show;
pub use core::num::{Num, div_rem, Zero, zero, One, one};
pub use core::num::{Signed, abs, abs_sub, signum};
pub use core::num::{Signed, abs, signum};
pub use core::num::{Unsigned, pow, Bounded};
pub use core::num::{Primitive, Int, Saturating};
pub use core::num::{CheckedAdd, CheckedSub, CheckedMul, CheckedDiv};
@ -58,6 +58,11 @@ pub trait FloatMath: Float {
/// Returns the minimum of the two numbers.
fn min(self, other: Self) -> 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.
fn abs_sub(self, other: Self) -> Self;
/// Take the cubic root of a number.
fn cbrt(self) -> Self;
/// Calculate the length of the hypotenuse of a right-angle triangle given
@ -122,6 +127,13 @@ pub fn from_str_radix<T: FromStrRadix>(str: &str, radix: uint) -> Option<T> {
FromStrRadix::from_str_radix(str, radix)
}
// DEPRECATED
#[deprecated = "Use `FloatMath::abs_sub`"]
pub fn abs_sub<T: FloatMath>(x: T, y: T) -> T {
x.abs_sub(y)
}
/// Helper function for testing numeric operations
#[cfg(test)]
pub fn test_num<T:Num + NumCast + Show>(ten: T, two: T) {