-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Signed, Unsigned and Natural traits #6041
Conversation
This adds the following methods to ints and uints: - div - modulo - div_mod - quot_rem - gcd - lcm - divisible_by - is_even - is_odd I have not implemented Natural for BigInt and BigUInt because they're a little over my head.
@gifnksm I didn't want to mess up |
This looks excellent. Thanks! |
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.
Shouldn't the Natural methods take |
@bjz I'm sorry if my previous comment on #6013 made you nervous. But OK. I'll try to implement |
@gifnksm Heh, no worries! Yeah perhaps |
…ebroto Fix FP in `print_stdout` Fix rust-lang#6041 This lint shouldn't be emitted in `build.rs` as `println!` and `print!` are used for the build script. changelog: none
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:I have not implemented
Natural
forBigInt
andBigUInt
because they're a little over my head. Help with this would be most appreciated.