-
Notifications
You must be signed in to change notification settings - Fork 47
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 more number theory functions #10
base: master
Are you sure you want to change the base?
Conversation
Sorry I haven't reviewed this -- I'm mostly pondering what the public API should look like. I think you're probably right that |
I'm a bit concerned that the trait bounds are leaking implementation details. If we change the implementation and require different traits, it can easily become a breaking change.
Why? It is similar to returning a tuple, except that the fields are named. |
You only need the trait bounds for a generic or default impl. The alternative is to only macro-impl the primitives here, then implement bigint separately, and leave others to their own. That's not necessarily the greatest, but how many other I fought with this for My basic objection to public fields is that it makes it hard to make changes to the struct. You're right that it's an improvement over a plain tuple though, which also couldn't change. The more flexible path is an opaque struct with accessors, but then you can't easily unpack values. |
This would work. The other integer types mostly implement it anyway. What should the traits look like? Putting several functions into one trait makes it hard to extend, having one trait per function is probably inconvenient.
In this case, the only possible change I can think of is returning |
We could add a private field:
It would allow adding fields in future. |
Is there any hope for this getting merged? Would love to do modular inverses on bigint. |
Extended GCD was already merged in #19, so this should now build on top of that if possible.
Can it just be added to |
My implementation is not equivalent: It does not use The implementation currently part of I don't know which of the two signatures is preferable. The one on master with |
@cuviper Which option do you prefer?
|
FWIW, there's a 'num-modular` crate that have full support for modular operations. |
This implements the extended Euclidean algorithm, the modular inverse and modular exponentiation.
num-traits
.powm
should be part of a trait, because bigint libraries can implement it more efficiently.powm
are not pretty, because the existing traits were not enough.Fixes #3.