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

Diff of /projs/dtats/trunk/projs/2018/20180707_cgi_web_tools_aux_exe/dtats_cgi_aux_arith_large/subfunc_gcd.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 28  Line 28 
28  //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE  //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29  //SOFTWARE.  //SOFTWARE.
30  //********************************************************************************  //********************************************************************************
31  //This module is the GCD subfunction of a general-purpose CGI-BIN program to support  //This module is the GCD subfunction of a general-purpose CGI-BIN program to support
32  //number theory demonstration applications.    //number theory demonstration applications.
33  //  //
34  //INPUT PARAMETERS  //INPUT PARAMETERS
35  //----------------  //----------------
# Line 52  Line 52 
52  //        EQ     :  Other or unspecified error.  //        EQ     :  Other or unspecified error.
53  //  //
54  //[02] The fully normalized first integer entered.  This means it has been  //[02] The fully normalized first integer entered.  This means it has been
55  //     stripped of all weird characters, etc.  This can be used by the  //     stripped of all weird characters, etc.  This can be used by the
56  //     PHP script to repopulate the form boxes.  //     PHP script to repopulate the form boxes.
57  //[03] The fully normalized second integer entered.  //[03] The fully normalized second integer entered.
58  //  //
# Line 75  Line 75 
75  //this program will contain a number of lines which is a multiple of 5.  //this program will contain a number of lines which is a multiple of 5.
76  //  //
77  //The return value (exit code) from this subfunction is always 0.  //The return value (exit code) from this subfunction is always 0.
78  //  //
79    
80  #define MODULE_SUBFUNC_GCD  #define MODULE_SUBFUNC_GCD
81    
# Line 109  int SUBFUNC_GCD_main(int argc, char *arg Line 109  int SUBFUNC_GCD_main(int argc, char *arg
109        return(0);        return(0);
110        }        }
111    
112     //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.
113     //Leave 2 characters of space in case we assign a "0".     //Leave 2 characters of space in case we assign a "0".
114     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));
115     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 167  int SUBFUNC_GCD_main(int argc, char *arg Line 167  int SUBFUNC_GCD_main(int argc, char *arg
167     //We assume at this point that we will be successful.  Output     //We assume at this point that we will be successful.  Output
168     //the header stuff.     //the header stuff.
169     printf("S\n");     printf("S\n");
170     mpz_out_str(stdout, 10, alg_a);     mpz_out_str(stdout, 10, alg_a);
171     printf("\n");         printf("\n");
172     mpz_out_str(stdout, 10, alg_b);     mpz_out_str(stdout, 10, alg_b);
173     printf("\n");         printf("\n");
174    
175     //We require as an initial condition that a >= b.  Make     //We require as an initial condition that a >= b.  Make
176     //that happen.     //that happen.
# Line 190  int SUBFUNC_GCD_main(int argc, char *arg Line 190  int SUBFUNC_GCD_main(int argc, char *arg
190        {        {
191        //We are at next round.        //We are at next round.
192        round++;        round++;
193          
194        //Values for this round inherited from the last one.        //Values for this round inherited from the last one.
195        mpz_set(alg_a, alg_b);        mpz_set(alg_a, alg_b);
196        mpz_set(alg_b, alg_amodb);        mpz_set(alg_b, alg_amodb);
197        
198        //Calculate the quotient and remainder.        //Calculate the quotient and remainder.
199        mpz_fdiv_qr(alg_adivb, alg_amodb, alg_a, alg_b);        mpz_fdiv_qr(alg_adivb, alg_amodb, alg_a, alg_b);
200    
201        //Output all the data from the round.        //Output all the data from the round.
202        printf("%d\n", round);        printf("%d\n", round);
203        mpz_out_str(stdout, 10, alg_a);        mpz_out_str(stdout, 10, alg_a);
204        printf("\n");            printf("\n");
205        mpz_out_str(stdout, 10, alg_b);        mpz_out_str(stdout, 10, alg_b);
206        printf("\n");            printf("\n");
207        mpz_out_str(stdout, 10, alg_adivb);        mpz_out_str(stdout, 10, alg_adivb);
208        printf("\n");            printf("\n");
209        mpz_out_str(stdout, 10, alg_amodb);        mpz_out_str(stdout, 10, alg_amodb);
210        printf("\n");            printf("\n");
211        }        }
212     while((round < 2000) && (mpz_sgn(alg_amodb) > 0));     while((round < 2000) && (mpz_sgn(alg_amodb) > 0));
213    
214     //The GCD canonically will be the last non-zero remainder.     //The GCD canonically will be the last non-zero remainder.
215     mpz_out_str(stdout, 10, alg_b);     mpz_out_str(stdout, 10, alg_b);
216     printf("\n");         printf("\n");
217    
218     //Finally, we output the trailing "S".     //Finally, we output the trailing "S".
219     printf("S\n");     printf("S\n");
220    
221     return(0);     return(0);
222     }     }
223    
224  //********************************************************************************  //********************************************************************************
225  // End of SUBFUNC_GCD.C.  // End of SUBFUNC_GCD.C.

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

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25