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. |
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 |
|
|
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)); |
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); |
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. |