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

Avoid OverflowError in mpz.__rshift__() #525

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

skirpichev
Copy link
Contributor

Closes #524

@skirpichev skirpichev marked this pull request as draft October 17, 2024 07:26
@skirpichev
Copy link
Contributor Author

skirpichev commented Oct 17, 2024

@casevh, second patch removes scripts/mp_bitcnt_t.diff, thus I'm marking this as a draft.

It's possible to implement this pr in other way, but I think it triggers a bug in the patch. I think that proper support for 64-bit mp_bitcnt_t on win64 1) requires a more work, 2) we should submit patch to the upstream first.

@casevh
Copy link
Collaborator

casevh commented Oct 28, 2024

What bug is triggered in the mp_bitcnt_t patch? A previous bug that I reported upstream was fixed within a few days.

@skirpichev
Copy link
Contributor Author

What bug is triggered in the mp_bitcnt_t patch?

See failed job: https://github.com/aleaxit/gmpy/actions/runs/11379818079/job/31657941881

It's on Windows, I can't reproduce this. I guess, mpz_fdiv_q_2exp() make some assumptions on max value of the last argument.

@skirpichev
Copy link
Contributor Author

@casevh, I think failure with mp_bitcnt_t.diff happens, because mpz_fdiv_q_2exp() uses mpn_rshift() to do divisions. This will not work with fourth argument of mp_bitcnt_t type, because it's declared as

mp_limb_t mpn_rshift (mp_ptr, mp_srcptr, mp_size_t, unsigned int);

I don't see an easy fix.

What do you think?

@casevh
Copy link
Collaborator

casevh commented Nov 14, 2024

Per the GMP documentation, (the fourth argument) must be in the range 1 to mp_bits_per_limb{}-1. So I think there is a bug somewhere else. I'll try to step through the logic in cfdiv_q_2exp.

@skirpichev
Copy link
Contributor Author

FYI, failed test: assert (mpz(123) >> 111111111111111111111) == mpz(0)

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.

mpz(1)>>111111111111111111111 raises OverflowError
2 participants