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

Fix #49 #51

Merged
merged 2 commits into from
Jul 18, 2019
Merged

Fix #49 #51

merged 2 commits into from
Jul 18, 2019

Conversation

maxbla
Copy link
Contributor

@maxbla maxbla commented Jun 17, 2019

fixed issue #49
added a test case for it

Side note:
cmp is a bit scary. Do we know what it's amortized runtime is? It seems to me that the worst case (having to compare the reciprocals many times) could be pretty bad. Is there any way to have a separate impl for T: Clone + Integer + CheckedMul? As the comments note, CheckedMul would make the implementation faster. I messed around, but I can't find a way to have two implementations -- one for checked and one for no checked. I found an this RFC for negative trait bounds though (spoiler: negative trait bounds are not happening soon).

src/lib.rs Show resolved Hide resolved
@MattX
Copy link
Contributor

MattX commented Jun 25, 2019

Do we know what it's amortized runtime is?

It's effectively performing Euclid's algorithm, so its runtime is O(n) assuming all operations take constant time (so more than that for BigInts, details in the linked Stackoverflow answer). I think it would be a great idea to include that in the impl block documentation as it's not obvious.

Edit: O(n) where n is the number of bits in the smaller of the two denominators.

Is there any way to have a separate impl for T: Clone + Integer + CheckedMul?

FYI I'm pretty sure you're right that we can't, we'd need specialization (or, as you mention, negative traits, but these seem even less likely to land soon).

The changes in the CR look good to me but I'm not a member so that's not worth much :p

src/lib.rs Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
Co-Authored-By: Josh Stone <cuviper@gmail.com>
@cuviper
Copy link
Member

cuviper commented Jul 18, 2019

bors r+

bors bot added a commit that referenced this pull request Jul 18, 2019
51: Fix #49 r=cuviper a=maxbla

fixed issue #49 
added a test case for it

Side note:
`cmp` is a bit scary. Do we know what it's amortized runtime is? It seems to me that the worst case (having to compare the reciprocals many times) could  be pretty bad. Is there any way to have a separate `impl` for `T: Clone + Integer + CheckedMul`? As the comments note, CheckedMul would make the implementation faster. I messed around, but I can't find a way to have two implementations -- one for checked and one for no checked. I found an [this](rust-lang/rfcs#586) RFC for negative trait bounds though (spoiler: negative trait bounds are not happening soon).

Co-authored-by: Max Blachman <blachmanmax@gmail.com>
@bors
Copy link
Contributor

bors bot commented Jul 18, 2019

Build succeeded

@bors bors bot merged commit f38ff9c into rust-num:master Jul 18, 2019
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.

3 participants