Skip to content
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

Merged
merged 4 commits into from
Mar 8, 2018
Merged

Implement is_one and Inv for Ratio. #19

merged 4 commits into from
Mar 8, 2018

Conversation

clarfonthey
Copy link
Contributor

Requires a new version of num-traits to be pushed but I figured I'd offer this anyway.

@clarfonthey clarfonthey changed the title Implement is_one for Ratio. Implement is_one and Inv for Ratio. Feb 27, 2018
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>
Copy link
Member

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> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*inv

@clarfonthey
Copy link
Contributor Author

Will work once num-bigint 0.2.1 is released

@clarfonthey clarfonthey mentioned this pull request Mar 4, 2018

#[inline]
fn is_one(&self) -> bool {
self.numer == self.denom
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

@clarfonthey clarfonthey Mar 5, 2018

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_asserts 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"
Copy link
Member

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.

Copy link
Member

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.)

Copy link
Contributor Author

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. ><

@clarfonthey
Copy link
Contributor Author

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.

@cuviper
Copy link
Member

cuviper commented Mar 5, 2018

Are the changes to bounds actually useful? If you can't even call Ratio::new, then I'm not sure what use-case this is trying to support.

(In general, I'd prefer you didn't combine unrelated changes into one PR.)

@clarfonthey
Copy link
Contributor Author

@cuviper will remove those then

@clarfonthey
Copy link
Contributor Author

Reverted those changes, so, things should be ready to merge.

@cuviper
Copy link
Member

cuviper commented Mar 8, 2018

Thanks!

bors r+

bors bot added a commit that referenced this pull request Mar 8, 2018
19: Implement is_one and Inv for Ratio. r=cuviper a=clarcharr

Requires a new version of `num-traits` to be pushed but I figured I'd offer this anyway.
@bors
Copy link
Contributor

bors bot commented Mar 8, 2018

Build succeeded

@bors bors bot merged commit b416609 into rust-num:master Mar 8, 2018
bors bot added a commit that referenced this pull request Jun 16, 2018
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]>
bors bot added a commit that referenced this pull request Jun 16, 2018
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants