/[dtapublic]/projs/dtats/trunk/projs/2018/20180707_cgi_web_tools_aux_exe/dtats_cgi_aux_arith_large/subfunc_gmp_prob_prime.c
ViewVC logotype

Diff of /projs/dtats/trunk/projs/2018/20180707_cgi_web_tools_aux_exe/dtats_cgi_aux_arith_large/subfunc_gmp_prob_prime.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 206 by dashley, Sat Jul 14 00:10:29 2018 UTC revision 207 by dashley, Sun Jul 15 21:50:56 2018 UTC
# Line 40  Line 40 
40  //INPUT PARAMETERS  //INPUT PARAMETERS
41  //----------------  //----------------
42  //The subfunction accepts two parameters, the integers whose primality is to be  //The subfunction accepts two parameters, the integers whose primality is to be
43  //assessed, and the number of reps (passed directly to the GMP function).    //assessed, and the number of reps (passed directly to the GMP function).
44  //Naturally, the integers should be positive.  Invalid integers are assigned  //Naturally, the integers should be positive.  Invalid integers are assigned
45  //defaults.  It is the responsibility of the calling script to do whatever  //defaults.  It is the responsibility of the calling script to do whatever
46  //sanity checking is desired.  //sanity checking is desired.
# Line 69  Line 69 
69  //and the first and last line will be "S".  //and the first and last line will be "S".
70  //  //
71  //The return value (exit code) from this subfunction is always 0.  //The return value (exit code) from this subfunction is always 0.
72  //  //
73    
74  #define MODULE_SUBFUNC_GMP_PROB_PRIME  #define MODULE_SUBFUNC_GMP_PROB_PRIME
75    
# Line 108  int SUBFUNC_GMP_PROB_PRIME_main(int argc Line 108  int SUBFUNC_GMP_PROB_PRIME_main(int argc
108        return(0);        return(0);
109        }        }
110    
111     //Copy the command-line arguments to a safe place where we can manipulate them.       //Copy the command-line arguments to a safe place where we can manipulate them.
112     //Leave 2 characters of space in case we assign a "0".     //Leave 2 characters of space in case we assign a "0".
113     arg1 = (char *)malloc((AUXFUNCS_size_t_max(1, strlen(argv[2])) + 1) * sizeof(char));     arg1 = (char *)malloc((AUXFUNCS_size_t_max(1, strlen(argv[2])) + 1) * sizeof(char));
114     arg2 = (char *)malloc((AUXFUNCS_size_t_max(1, strlen(argv[3])) + 1) * sizeof(char));     arg2 = (char *)malloc((AUXFUNCS_size_t_max(1, strlen(argv[3])) + 1) * sizeof(char));
# Line 158  int SUBFUNC_GMP_PROB_PRIME_main(int argc Line 158  int SUBFUNC_GMP_PROB_PRIME_main(int argc
158     mpz_set_str(number_to_test, arg1, 10);     mpz_set_str(number_to_test, arg1, 10);
159     mpz_set_str(nreps_mpz,      arg2, 10);     mpz_set_str(nreps_mpz,      arg2, 10);
160    
161     //We don't want to allow any more than 5000 repetitions for that     //We don't want to allow any more than 5000 repetitions for that
162     //parameter.  So, if it is larger than 5000, whack it down.     //parameter.  So, if it is larger than 5000, whack it down.
163     if (mpz_cmp_d(nreps_mpz, (double)5000) > 0)     if (mpz_cmp_d(nreps_mpz, (double)5000) > 0)
164        mpz_set_str(nreps_mpz, "5000", 10);        mpz_set_str(nreps_mpz, "5000", 10);
# Line 167  int SUBFUNC_GMP_PROB_PRIME_main(int argc Line 167  int SUBFUNC_GMP_PROB_PRIME_main(int argc
167     //a normal integer.     //a normal integer.
168     nreps_native = mpz_get_si(nreps_mpz);     nreps_native = mpz_get_si(nreps_mpz);
169    
170     //Run the GMP library function to guess at primality and get the result     //Run the GMP library function to guess at primality and get the result
171     //back.     //back.
172     gmp_result = mpz_probab_prime_p(number_to_test, nreps_native);     gmp_result = mpz_probab_prime_p(number_to_test, nreps_native);
173    
174     //Now, write the output block.     //Now, write the output block.
175     printf("S\n");     printf("S\n");
176     mpz_out_str(stdout, 10, number_to_test);     mpz_out_str(stdout, 10, number_to_test);
177     printf("\n");         printf("\n");
178     mpz_out_str(stdout, 10, nreps_mpz);     mpz_out_str(stdout, 10, nreps_mpz);
179     printf("\n");     printf("\n");
180     printf("%d\n", gmp_result);     printf("%d\n", gmp_result);
181     printf("S\n");     printf("S\n");
182    
183     //Always return 0.     //Always return 0.
184     return(0);     return(0);
185     }     }
186    
187  //********************************************************************************  //********************************************************************************
188  // End of SUBFUNC_GMP_PROB_PRIME.C.  // End of SUBFUNC_GMP_PROB_PRIME.C.

Legend:
Removed from v.206  
changed lines
  Added in v.207

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25