]> git.lizzy.rs Git - rust.git/commit
auto merge of #6041 : bjz/rust/numeric-traits, r=brson
authorbors <bors@rust-lang.org>
Wed, 24 Apr 2013 05:12:47 +0000 (22:12 -0700)
committerbors <bors@rust-lang.org>
Wed, 24 Apr 2013 05:12:47 +0000 (22:12 -0700)
commitc8ac057545f7b2edf1e488aa4562138a6ed7a096
tree4c67cea5512e5f0cceeda17b3f2b905c4202bd36
parent706096b31960143fb1eb957a882f170ae4a8b4e9
parentab8068c9f2cbcce4411020b04dafe2055044f96a
auto merge of #6041 : bjz/rust/numeric-traits, r=brson

As part of the numeric trait reform (see issue #4819), I have added the following traits to `core::num` and implemented them for the appropriate types:

~~~rust
pub trait Signed: Num
                + Neg<Self> {
    fn abs(&self) -> Self;
    fn signum(&self) -> Self;
    fn is_positive(&self) -> bool;
    fn is_negative(&self) -> bool;
}

pub trait Unsigned: Num {}

pub trait Natural: Num
                 + Ord
                 + Quot<Self,Self>
                 + Rem<Self,Self> {
    fn div(&self, other: Self) -> Self;
    fn modulo(&self, other: Self) -> Self;
    fn div_mod(&self, other: Self) -> (Self,Self);
    fn quot_rem(&self, other: Self) -> (Self,Self);

    fn gcd(&self, other: Self) -> Self;
    fn lcm(&self, other: Self) -> Self;
    fn divisible_by(&self, other: Self) -> bool;
    fn is_even(&self) -> bool;
    fn is_odd(&self) -> bool;
}
~~~

I have not implemented `Natural` for `BigInt` and `BigUInt` because they're a little over my head. Help with this would be most appreciated.