-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
make cmp with BigInt return in [-1, 0, 1] #28780
Conversation
This is to adhere to the documentation.
test/bigint.jl
Outdated
bigrand() = rand(-big(2)^rand(1:rand(1:1000)):big(2)^rand(1:rand(1:1000))) | ||
for T in (Base.BitInteger_types..., BigInt, Float64, Float32, Float16, BigFloat) | ||
@test cmp(big(2)^130, one(T)) == 1 | ||
@test cmp(-big(2)^130, one(T)) == -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about testing these with ===
to ensure that the type matches as well? And throw in some tests where the result is 0
as well...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done. I removed the testing with BigFloat
as this is handled in the MPFR
module, and can return Int32
. I can make a PR for MPFR
if you think it's useful.
* make cmp with BigInt return in [-1, 0, 1] (cherry picked from commit 472c178)
* make cmp with BigInt return in [-1, 0, 1]
* make cmp with BigInt return in [-1, 0, 1] (cherry picked from commit 472c178)
* make cmp with BigInt return in [-1, 0, 1] (cherry picked from commit 472c178)
* make cmp with BigInt return in [-1, 0, 1] (cherry picked from commit 472c178)
This is to adhere to the documentation.
The added
sign
call doesn't seem to add overhead to the comparison functions usingcmp
. Adding thissign
call forcmp(::BigInt, ::UInt)
seems unnecessary according to the current GMP implementation ofmpz_cmp_ui
, but it's more maintenable to rely only on the documentation (which doesn't make garranties). A similar treatment could be made for MPFR, but my few tries didn't find a case where the values is not in[-1, 0, 1]
.