Thanks for pointing that out. I just noticed it myself, after pulling hairs 
out for a few hours :( I guess this is a documentation bug, or something...

Regards,
Mihai

On Sunday, June 24, 2012 11:29:36 PM UTC+2, casevh wrote:
>
> On Sun, Jun 24, 2012 at 2:21 PM, michael85 <todormi...@gmail.com> wrote: 
> > There's a small copy / paste gone wrong issue in the code: 
> mpz_powm_ui(out, 
> > x, -1UL, n). Unfortunately, even after I remove the UL, the behavior is 
> the 
> > same. 
>
> You can't pass a negative value  as an unsigned long parameter. -1UL 
> is really to 2**32 - 1. Just create another mpz_t for the exponent and 
> set it to -1. 
>
> casevh 
> > 
> > Mihai 
> > 
> > 
> > On Sunday, June 24, 2012 10:47:36 PM UTC+2, michael85 wrote: 
> >> 
> >> Hello Everyone, 
> >> 
> >> For some reason, I am not able to understand why the following code 
> prints 
> >> different results: 
> >> 
> >>     mpz_t x, n, out; 
> >> 
> >>     mpz_init_set_ui(x, 2UL); 
> >>     mpz_init_set_ui(n, 7UL); 
> >>     mpz_init(out); 
> >> 
> >>     mpz_invert(out, x, n); 
> >>     gmp_printf ("%Zd\n", out);//prints 4. 2 * 4 (mod 7) = 1. OK 
> >> 
> >>     mpz_powm_ui(out, x, -1UL, n);//prints 1. 2 * 1 (mod 7) = 2. How 
> come? 
> >>     gmp_printf ("%Zd\n", out); 
> >> 
> >>     mpz_clear(x); 
> >>     mpz_clear(n); 
> >>     mpz_clear(out); 
> >> 
> >> The documentation states that negative exponents are supported by 
> mpz_powm 
> >> if base^-1 nod n exists. This behavior is the same as in GMP 4.1 on 
> Windows. 
> >> What am I missing here? 
> >> 
> >> Best regards, 
> >> Mihai Todor 
>

-- 
You received this message because you are subscribed to the Google Groups 
"mpir-devel" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/mpir-devel/-/JABt6JCRfTAJ.
To post to this group, send email to mpir-devel@googlegroups.com.
To unsubscribe from this group, send email to 
mpir-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/mpir-devel?hl=en.

Reply via email to