Skip to content

objint_mpz: Fix pow3(1,2,0). #17716

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions py/objint_mpz.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,10 @@ static mpz_t *mp_mpz_for_int(mp_obj_t arg, mpz_t *temp) {
mp_obj_t mp_obj_int_pow3(mp_obj_t base, mp_obj_t exponent, mp_obj_t modulus) {
if (!mp_obj_is_int(base) || !mp_obj_is_int(exponent) || !mp_obj_is_int(modulus)) {
mp_raise_TypeError(MP_ERROR_TEXT("pow() with 3 arguments requires integers"));
} else if (modulus == MP_OBJ_NEW_SMALL_INT(0)) {
mp_raise_ValueError(MP_ERROR_TEXT("divide by zero"));
} else {
mp_obj_t result = mp_obj_new_int_from_ull(0); // Use the _from_ull version as this forces an mpz int
mp_obj_int_t *res_p = (mp_obj_int_t *)MP_OBJ_TO_PTR(result);
mp_obj_int_t *res_p = mp_obj_int_new_mpz();

mpz_t l_temp, r_temp, m_temp;
mpz_t *lhs = mp_mpz_for_int(base, &l_temp);
Expand All @@ -376,7 +377,7 @@ mp_obj_t mp_obj_int_pow3(mp_obj_t base, mp_obj_t exponent, mp_obj_t modulus) {
if (mod == &m_temp) {
mpz_deinit(mod);
}
return result;
return MP_OBJ_FROM_PTR(res_p);
}
}
#endif
Expand Down
4 changes: 4 additions & 0 deletions tests/basics/builtin_pow3_intbig.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@
print(hex(pow(y, x-1, x))) # Should be 1, since x is prime
print(hex(pow(y, y-1, x))) # Should be a 'big value'
print(hex(pow(y, y-1, y))) # Should be a 'big value'
try:
print(pow(1,2,0))
except ValueError:
print("ValueError")
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy