20211103, 17:34  #12 
Sep 2002
Database er0rr
2·5·397 Posts 

20211103, 17:39  #13 
Mar 2016
3×5^{3} Posts 

20211103, 17:44  #14  
Sep 2002
Database er0rr
F82_{16} Posts 
Quote:
Last fiddled with by paulunderwood on 20211103 at 17:52 

20211103, 17:52  #15 
Mar 2016
3×5^{3} Posts 

20211113, 19:11  #16 
Mar 2016
3·5^{3} Posts 
A peaceful and pleasant day for you,
there is a bug in the function, and I have no idea, where the reason is: void mpz_mod_mp (mpz_t r, mpz_t a, uint64 p) { mpz_t res_1, res_2; mpz_init (res_1); mpz_init (res_2); // 1. Calculation mpz_mod (res_1, a, f); // 2. Calculation mp_bitcnt_t mp=mp_bitcnt_t(p); // assumed that r is initialized and a is expendable if (mpz_cmp_ui (a, 0)==0) { mpz_set_ui (res_2, 0); } else { do { mpz_fdiv_r_2exp (res_2, a, mp); mpz_fdiv_q_2exp (a, a, mp); mpz_add (res_2, res_2, a); } while (mpz_sizeinbase (res_2,2) > mp); } // Compairison if (mpz_cmp (res_1, res_2)!=0) { mpz_out_str (stdout, 10, a); cout << endl; mpz_out_str (stdout, 10, res_1); cout << endl; mpz_out_str (stdout, 10, res_2); cout << endl; exit (1); } mpz_set (r, res_2); mpz_clear (res_1); mpz_clear (res_2); } The error appears if a=0 and the output is 0 10584739298409185657387898722659423897260 89430325577680987480245132687307139815991 If you have an idea, where the error is, I will be glad. 
20211113, 19:24  #17  
Sep 2002
Database er0rr
F82_{16} Posts 
Quote:
What is f? Last fiddled with by paulunderwood on 20211113 at 19:32 

20211113, 19:44  #18  
Mar 2016
3×5^{3} Posts 
Quote:
f is Mp as mpz_t variable But why is res_1 and res_2 not equal 0 ? In other cases res_1 and res_2 are the same. 

20211113, 19:51  #19 
Sep 2002
Database er0rr
3970_{10} Posts 

20211113, 20:01  #20 
Mar 2016
3·5^{3} Posts 

20211113, 20:08  #21 
Sep 2002
Database er0rr
7602_{8} Posts 

20211113, 20:18  #22 
Sep 2002
Database er0rr
2·5·397 Posts 

Thread Tools  
Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Factorial modulo a prime  axn  Computer Science & Computational Number Theory  66  20110901 21:55 
modulo operation for polynomials?  smslca  Math  3  20110418 17:18 
Order of 3 modulo a Mersenne prime  T.Rex  Math  7  20090313 10:46 
N! modulo for large N  Cyclamen Persicum  Math  2  20031210 10:52 
The modulo operation, how is it computed?  eepiccolo  Math  7  20030108 03:07 