about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-05-07 16:18:37 -0700
committerbors <bors@rust-lang.org>2013-05-07 16:18:37 -0700
commit847552f48b51aec0fcc6b7fd2ee2a51f3700321a (patch)
tree591d59854d9ea4edfa1777406d1ec12efff7f25e /src/libstd
parent3a34e93651cb84536a23f9cdb6290bdee6446264 (diff)
parentcc51186be0c68897042a72bd52147e345ad2a2cd (diff)
downloadrust-847552f48b51aec0fcc6b7fd2ee2a51f3700321a.tar.gz
rust-847552f48b51aec0fcc6b7fd2ee2a51f3700321a.zip
auto merge of #6301 : bjz/rust/numeric-traits, r=pcwalton
This is part of the redesign of the numeric traits tracked in issue #4819.

Renamed:

- `Exponential::expm1` -> `Float::exp_m1` - for consistency with underscore usage elsewhere
- `Exponential::log` -> `Exponential::ln` - a less ambiguous name for the natural logarithm
- `{float, f64, f32}::logarithm` -> `Exponential::log` - for arbitrary base logarithms
- `Real::log_2` -> `Real::ln_2`  - for consistency with `ln`
- `Real::log_10` -> `Real::ln_10` - for consistency with `ln`

Added:

- `Signed::abs_sub` - wraps libm's `fdim` function
- `Float::is_normal` - returns `true` if the number is neither zero, infinite, subnormal or NaN
- `Float::classify` - returns the floating point category of the number
- `Float::ln_1p` - returns the natural logarithm of the number plus one
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/num/bigint.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libstd/num/bigint.rs b/src/libstd/num/bigint.rs
index cd347098e25..a5cf929ed93 100644
--- a/src/libstd/num/bigint.rs
+++ b/src/libstd/num/bigint.rs
@@ -832,6 +832,11 @@ impl Signed for BigInt {
     }
 
     #[inline(always)]
+    fn abs_sub(&self, other: &BigInt) -> BigInt {
+        if *self <= *other { Zero::zero() } else { *self - *other }
+    }
+
+    #[inline(always)]
     fn signum(&self) -> BigInt {
         match self.sign {
             Plus  => BigInt::from_biguint(Plus, One::one()),
@@ -1921,6 +1926,15 @@ mod bigint_tests {
     }
 
     #[test]
+    fn test_abs_sub() {
+        assert_eq!((-One::one::<BigInt>()).abs_sub(&One::one()), Zero::zero());
+        assert_eq!(One::one::<BigInt>().abs_sub(&One::one()), Zero::zero());
+        assert_eq!(One::one::<BigInt>().abs_sub(&Zero::zero()), One::one());
+        assert_eq!(One::one::<BigInt>().abs_sub(&-One::one::<BigInt>()),
+                   IntConvertible::from_int(2));
+    }
+
+    #[test]
     fn test_to_str_radix() {
         fn check(n: int, ans: &str) {
             assert!(ans == IntConvertible::from_int::<BigInt>(n).to_str_radix(10));