Re: mini-gmp mpz_powm incorrect result

2022-09-29 Thread Marco Bodrato
Ciao, Il 2022-09-05 21:23 ni...@lysator.liu.se ha scritto: Marco Bodrato writes: I propose to also add a couple of tests to mini-gmp/tests/t-powm.c , to keep track of this. Definitely needed, thanks for looking into that. + if (mpz_cmp_ui (res, 1) <= 0) +mpz_add_ui (res, res, 9);

Re: mini-gmp mpz_powm incorrect result

2022-09-29 Thread Niels Möller
Marco Bodrato writes: >>> or even (mn == 0 check just above this code rules out |m| < 1) >>> >>>mpz_set_ui (r, mpz_cmpabs_ui (m, 1)); > > I agree with this solution. Will you commit it? Committed, and I've verified that it fixes Guido's test case. > I propose to also add a couple of tests

Re: mini-gmp mpz_powm incorrect result

2022-09-29 Thread Marco Bodrato
Ciao, Il 2022-08-30 10:25 Vincent Lefevre ha scritto: or even (mn == 0 check just above this code rules out |m| < 1) mpz_set_ui (r, mpz_cmpabs_ui (m, 1)); I agree with this solution. Will you commit it? Concerning this second solution, the GMP manual says: -- Function: int

Re: mini-gmp mpz_powm incorrect result

2022-09-29 Thread Marco Bodrato
Il 2022-09-05 19:04 Marco Bodrato ha scritto: Il 2022-08-30 10:25 Vincent Lefevre ha scritto: or even (mn == 0 check just above this code rules out |m| < 1) mpz_set_ui (r, mpz_cmpabs_ui (m, 1)); I agree with this solution. Will you commit it? I incorrectly removed the "Niels Möller

Re: mini-gmp mpz_powm incorrect result

2022-08-30 Thread Niels Möller
Paul Zimmermann writes: > $ diff -u mini-gmp.c.orig mini-gmp.c > --- mini-gmp.c.orig 2022-08-29 10:28:20.700995412 +0200 > +++ mini-gmp.c 2022-08-29 10:27:36.112191428 +0200 > @@ -3060,6 +3060,7 @@ >if (en == 0) > { >mpz_set_ui (r, 1); > + mpz_tdiv_r (r, r, m); >

Re: mini-gmp mpz_powm incorrect result

2022-08-29 Thread Guido Vranken
Thank you, I have confirmed that your patch resolves the issue. On Mon, Aug 29, 2022 at 10:29 AM Paul Zimmermann wrote: > thank you, I confirm the bug, here is a potential fix: > > $ diff -u mini-gmp.c.orig mini-gmp.c > --- mini-gmp.c.orig 2022-08-29 10:28:20.700995412 +0200 > +++

Re: mini-gmp mpz_powm incorrect result

2022-08-29 Thread Paul Zimmermann
thank you, I confirm the bug, here is a potential fix: $ diff -u mini-gmp.c.orig mini-gmp.c --- mini-gmp.c.orig 2022-08-29 10:28:20.700995412 +0200 +++ mini-gmp.c 2022-08-29 10:27:36.112191428 +0200 @@ -3060,6 +3060,7 @@ if (en == 0) { mpz_set_ui (r, 1); + mpz_tdiv_r (r,

mini-gmp mpz_powm incorrect result

2022-08-28 Thread Guido Vranken
The following program computes 1^0 % 1: //#include #include "mini-gmp.c" #include #define CF_CHECK_EQ(expr, res) if ( (expr) != (res) ) { goto end; } int main(void) { mpz_t a, b, c, res; char* s = NULL; /* noret */ mpz_init(a); /* noret */ mpz_init(b); /* noret */