-
Notifications
You must be signed in to change notification settings - Fork 50
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 is_one and Inv for Ratio. #19
Conversation
src/lib.rs
Outdated
@@ -715,6 +715,28 @@ impl<'a, T> Neg for &'a Ratio<T> | |||
} | |||
} | |||
|
|||
impl<T> Inv for Ratio<T> | |||
where T: Clone + Integer + Inv<Output = T> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need T: Inv
-- in fact I expect no integers would have it.
src/lib.rs
Outdated
type Output = Ratio<T>; | ||
|
||
#[inline] | ||
fn neg(self) -> Ratio<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*inv
Will work once |
|
||
#[inline] | ||
fn is_one(&self) -> bool { | ||
self.numer == self.denom |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we consider the degenerate 0/0
case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, considering how 0/0
is an invalid state for Ratio
, I'd assume that it shouldn't be worried about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair, and is_zero
doesn't worry about it either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about it, I'll add some debug_assert
s to verify that the denominator is nonzero so that these can be caught in debug mode, but won't be checked on release.
I'll do this in a separate PR.
Cargo.toml
Outdated
@@ -16,15 +16,15 @@ readme = "README.md" | |||
|
|||
[dependencies.num-bigint] | |||
optional = true | |||
version = "0.2.0-git" | |||
version = "0.2.1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed?
num-bigint, complex, and rational are all currently in a transition to 0.2, and haven't been published at all yet -- thus the git
dependency. But I don't see why this PR would depend on bigint anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(If you want your new num-traits implementations in these traits sooner, please follow up with PRs to their 0.1.x branches.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wasn't compiling for me and I was a bit confused, and then I realised that I had to run cargo update
. ><
Okay, everything should be working now. I relaxed some of the bounds on the methods and hopefully that should be okay; please take a look at the latest commit to make sure everything is reasonable. |
Are the changes to bounds actually useful? If you can't even call (In general, I'd prefer you didn't combine unrelated changes into one PR.) |
@cuviper will remove those then |
Reverted those changes, so, things should be ready to merge. |
Thanks! bors r+ |
Build succeeded |
21: Implement Pow r=cuviper a=clarcharr Should be merged after #19, as this PR depends on that one. Fixes #20. Will need to investigate compile time increases that this change causes. Co-authored-by: Clar Charr <[email protected]> Co-authored-by: Josh Stone <[email protected]>
21: Implement Pow r=cuviper a=clarcharr Should be merged after #19, as this PR depends on that one. Fixes #20. Will need to investigate compile time increases that this change causes. Co-authored-by: Clar Charr <[email protected]> Co-authored-by: Josh Stone <[email protected]>
Requires a new version of
num-traits
to be pushed but I figured I'd offer this anyway.