diff options
| author | Brendan Zabarauskas <bjzaba@yahoo.com.au> | 2014-11-09 17:24:14 +1100 |
|---|---|---|
| committer | Brendan Zabarauskas <bjzaba@yahoo.com.au> | 2014-11-13 02:02:44 +1100 |
| commit | 9fe94bd995ab13afab7078a708b01f365740d2cd (patch) | |
| tree | e92121add768458f0055949991505c17c272f400 /src/libstd | |
| parent | e6db701d5b09c169297aaaf2d5d53f64bcb4676e (diff) | |
| download | rust-9fe94bd995ab13afab7078a708b01f365740d2cd.tar.gz rust-9fe94bd995ab13afab7078a708b01f365740d2cd.zip | |
Move abs_sub to FloatMath
This removes the need for libcore to depend on libm. `abs_sub` is not as useful for integers.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/num/f32.rs | 5 | ||||
| -rw-r--r-- | src/libstd/num/f64.rs | 5 | ||||
| -rw-r--r-- | src/libstd/num/mod.rs | 14 |
3 files changed, 23 insertions, 1 deletions
diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs index 175b1612b7e..6e2e8b8752f 100644 --- a/src/libstd/num/f32.rs +++ b/src/libstd/num/f32.rs @@ -109,6 +109,11 @@ impl FloatMath for f32 { } #[inline] + fn abs_sub(self, other: f32) -> f32 { + unsafe { cmath::fdimf(self, other) } + } + + #[inline] fn cbrt(self) -> f32 { unsafe { cmath::cbrtf(self) } } diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs index eb8e8db798c..591ca3486d2 100644 --- a/src/libstd/num/f64.rs +++ b/src/libstd/num/f64.rs @@ -117,6 +117,11 @@ impl FloatMath for f64 { } #[inline] + fn abs_sub(self, other: f64) -> f64 { + unsafe { cmath::fdim(self, other) } + } + + #[inline] fn cbrt(self) -> f64 { unsafe { cmath::cbrt(self) } } diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index ffe162cbc64..3f8504f4553 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -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) { |
