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

pow(int, int, fmpz) is always 1 #92

Closed
haru-44 opened this issue Oct 2, 2023 · 3 comments · Fixed by #93
Closed

pow(int, int, fmpz) is always 1 #92

haru-44 opened this issue Oct 2, 2023 · 3 comments · Fixed by #93

Comments

@haru-44
Copy link

haru-44 commented Oct 2, 2023

In python-flint==0.4.4.

>>> from flint import fmpz
>>> pow(2, 5, 1000)
32
>>> pow(2, 5, fmpz(1000))
1
>>> pow(2, fmpz(5), fmpz(1000))
32
@oscarbenjamin
Copy link
Collaborator

Looks like the code here should be checking the type of s:

def __pow__(s, t, m):
cdef fmpz_struct tval[1]
cdef fmpz_struct mval[1]
cdef int ttype = FMPZ_UNKNOWN
cdef int mtype = FMPZ_UNKNOWN
cdef int success
u = NotImplemented
ttype = fmpz_set_any_ref(tval, t)
if ttype == FMPZ_UNKNOWN:
return NotImplemented

I hadn't contemplated that __pow__(s, t, m) might be called with s not being an fmpz. At this line s will be an int (PyLong):
fmpz_powm((<fmpz>u).val, (<fmpz>s).val, tval, mval)

Presumably the bytes there look like a 1 as an fmpz_t.

The fix is that the s argument should be handled in the same way as the t argument.

@oscarbenjamin
Copy link
Collaborator

Thanks for the bug report. This will be fixed in the next release.

@haru-44
Copy link
Author

haru-44 commented Oct 2, 2023

Thanks for the correction.

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 a pull request may close this issue.

2 participants