diff options
| author | Brendan Zabarauskas <bjzaba@yahoo.com.au> | 2014-02-17 07:20:01 +1100 |
|---|---|---|
| committer | Brendan Zabarauskas <bjzaba@yahoo.com.au> | 2014-02-22 01:45:29 +1100 |
| commit | 3a9eca3a7be3ea156147fb8ed00a6447112e74d7 (patch) | |
| tree | 9d1d53b859766fcb40a293ab43fb5d235bc981ea /src/libstd/num/mod.rs | |
| parent | 2fa7d6b44fcc329e849f4dd43e11c6fdd43ebd76 (diff) | |
| download | rust-3a9eca3a7be3ea156147fb8ed00a6447112e74d7.tar.gz rust-3a9eca3a7be3ea156147fb8ed00a6447112e74d7.zip | |
Move std::num::Integer to libnum
Diffstat (limited to 'src/libstd/num/mod.rs')
| -rw-r--r-- | src/libstd/num/mod.rs | 34 |
1 files changed, 7 insertions, 27 deletions
diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index 8a417096c3e..332eb62b0c6 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -33,6 +33,12 @@ pub trait Num: Eq + Zero + One + Div<Self,Self> + Rem<Self,Self> {} +/// Simultaneous division and remainder +#[inline] +pub fn div_rem<T: Div<T, T> + Rem<T, T>>(x: T, y: T) -> (T, T) { + (x / y, x % y) +} + /// Defines an additive identity element for `Self`. /// /// # Deriving @@ -122,31 +128,6 @@ pub trait Signed: Num pub trait Unsigned: Num {} -pub trait Integer: Num - + Ord - + Div<Self,Self> - + Rem<Self,Self> { - fn div_rem(&self, other: &Self) -> (Self,Self); - - fn div_floor(&self, other: &Self) -> Self; - fn mod_floor(&self, other: &Self) -> Self; - fn div_mod_floor(&self, other: &Self) -> (Self,Self); - - fn gcd(&self, other: &Self) -> Self; - fn lcm(&self, other: &Self) -> Self; - - fn is_multiple_of(&self, other: &Self) -> bool; - fn is_even(&self) -> bool; - fn is_odd(&self) -> bool; -} - -/// Calculates the Greatest Common Divisor (GCD) of the number and `other`. -/// -/// The result is always positive. -#[inline(always)] pub fn gcd<T: Integer>(x: T, y: T) -> T { x.gcd(&y) } -/// Calculates the Lowest Common Multiple (LCM) of the number and `other`. -#[inline(always)] pub fn lcm<T: Integer>(x: T, y: T) -> T { x.lcm(&y) } - /// A collection of rounding operations. pub trait Round { /// Return the largest integer less than or equal to a number. @@ -270,8 +251,7 @@ pub trait Primitive: Clone + Bounded {} /// A collection of traits relevant to primitive signed and unsigned integers -pub trait Int: Integer - + Primitive +pub trait Int: Primitive + Bitwise + CheckedAdd + CheckedSub |
