-
Notifications
You must be signed in to change notification settings - Fork 148
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
Comments
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 |
If we cannot have these as |
Yes, I think we could reasonably have something comparing a |
That doesn't sound right to me. A comparison between two integers should never fail, such an API seems really frustrating for users. What are you supposed to do if it fails? Why not e.g. have a trait like |
We could make a new trait that's more capable, but I was thinking about what is possible with existing traits. So with |
I see what you mean. I guess that's clever and keeps the amount of code & traits down, although the usability would be a bit worse. |
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 beOrd
in the case ofBigInt
,BigUint
, andBigRational
, though comparisons involving complex numbers could not beOrd
. 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)
orx < 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.
The text was updated successfully, but these errors were encountered: