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

Feature: more comparison operations with BigInts #430

Open
Seltyk opened this issue Dec 3, 2023 · 1 comment
Open

Feature: more comparison operations with BigInts #430

Seltyk opened this issue Dec 3, 2023 · 1 comment

Comments

@Seltyk
Copy link

Seltyk commented Dec 3, 2023

Right now, the only comparison operation between BigInt types is PartialOrd<Rhs = Self>. There are times, however, that other comparisons are helpful, especially comparisons against primitive integer types. Most of these comparisons could be Ord in the case of BigInt, BigUint, and BigRational, though comparisons involving complex numbers could not be Ord. Even comparisons across differently-signed bigint types are trivial, simply adding an O(1) sign check before the vector-based comparing.

Admittedly, the primitive type comparison can be done already (e.g. x >= BigUint::from(8u64) or x < 16u64.into()), but this is inefficient in terms of time and memory.

Naturally, the reverse (primitive cmp bigint) would also be helpful, though thankfully implementing that will be trivial when the above implementation is made; it's the same source code with some text swapped around. I don't know much about macros, but this sounds like a job for macros.

@cuviper
Copy link
Member

cuviper commented Dec 3, 2023

We had this in development with rust-num/num-bigint#136, but I ran into type inferences in issue rust-num/num-bigint#150, and reverted in rust-num/num-bigint#151.

The inference issue is pretty nasty, because it even breaks code that would otherwise have nothing to do with bigints, just by the compiler seeing the additional trait implementations present at all. And I fully expect it would have the same result if we extended others like Ratio too.

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

No branches or pull requests

2 participants