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

Diff of /projs/dtats/trunk/projs/2018/20180707_cgi_web_tools_aux_exe/dtats_cgi_aux_arith_large/subfunc_cfbrap.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 29  Line 29 
29  //SOFTWARE.  //SOFTWARE.
30  //********************************************************************************  //********************************************************************************
31  //  //
32  //This module finds the best rational approximations to a rational number  //This module finds the best rational approximations to a rational number
33  //subject to constraints on the numerator and denominator using continued  //subject to constraints on the numerator and denominator using continued
34  //fraction techniques.  All of the algorithms employed are O(log N) so  //fraction techniques.  All of the algorithms employed are O(log N) so
35  //there should be no problem obtaining results for any practical problem.  //there should be no problem obtaining results for any practical problem.
# Line 56  Line 56 
56  //  //
57  // (f) The number of neighbors to the right of the specified number to return (max 1000).  // (f) The number of neighbors to the right of the specified number to return (max 1000).
58  //  //
59  // (g) The number of significant figures to use in floating-point results (note that  // (g) The number of significant figures to use in floating-point results (note that
60  //     "significant figures" includes the numbers before the decimal point as well as  //     "significant figures" includes the numbers before the decimal point as well as
61  //     after).  The maximum value here is 1000.  //     after).  The maximum value here is 1000.
62  //  //
# Line 95  Line 95 
95  //[02] The total number of lines in the output from the program, including the start  //[02] The total number of lines in the output from the program, including the start
96  //     and ending lines.  //     and ending lines.
97  //[03] The fully normalized numerator entered.  This means it has been  //[03] The fully normalized numerator entered.  This means it has been
98  //     stripped of all weird characters, etc.  This can be used by the  //     stripped of all weird characters, etc.  This can be used by the
99  //     PHP script to repopulate form boxes.  //     PHP script to repopulate form boxes.
100  //[04] The fully normalized denominator entered.  //[04] The fully normalized denominator entered.
101  //[05] The fully normalized maximum numerator entered.  //[05] The fully normalized maximum numerator entered.
# Line 106  Line 106 
106  //[10] The fully normalized number of CPU seconds allowed.  //[10] The fully normalized number of CPU seconds allowed.
107  //  //
108  //The next section of the output contains the decimal form of the number that is to  //The next section of the output contains the decimal form of the number that is to
109  //be approximated and also slightly more data about the number to be approximated.    //be approximated and also slightly more data about the number to be approximated.
110  //The PHP script may receive a number which is either specified as  //The PHP script may receive a number which is either specified as
111  //a rational number or as a decimal number, and the PHP script must convert it to a  //a rational number or as a decimal number, and the PHP script must convert it to a
112  //rational number so this program can process it.  Depending on what the PHP script  //rational number so this program can process it.  Depending on what the PHP script
# Line 148  Line 148 
148  //[N+10] Denominator of absolute value of error, irreducible with respect to numerator.  //[N+10] Denominator of absolute value of error, irreducible with respect to numerator.
149  //[N+11] Decimal form of absolute value of error, avoiding scientific notation if possible.  //[N+11] Decimal form of absolute value of error, avoiding scientific notation if possible.
150  //[N+12] Decimal form of absolute value of error, using scientific notation.  //[N+12] Decimal form of absolute value of error, using scientific notation.
151  //[N+13] Repeats at [N+2] for next neighbor, out to as many neighbors specified in  //[N+13] Repeats at [N+2] for next neighbor, out to as many neighbors specified in
152  //       [N+1]  //       [N+1]
153  //  //
154  //The next section of the output contains the continued fraction decomposition  //The next section of the output contains the continued fraction decomposition
# Line 167  Line 167 
167  //  //
168  //The next section of the output contains the continued fraction decomposition  //The next section of the output contains the continued fraction decomposition
169  //of the reciprocal of the number to approximate.  If the number to approximate is 0,  //of the reciprocal of the number to approximate.  If the number to approximate is 0,
170  //this entire section will be omitted.  //this entire section will be omitted.
171  //[N+ 0] Constant "CFINPUTRECIP".  //[N+ 0] Constant "CFINPUTRECIP".
172  //[N+ 1] Number of partial quotients to follow.  //[N+ 1] Number of partial quotients to follow.
173  //[N+ 2] k, subscript of iteration (first subscript is 0).  //[N+ 2] k, subscript of iteration (first subscript is 0).
# Line 214  Line 214 
214  //[N]    Constant "S", terminator line.  //[N]    Constant "S", terminator line.
215    
216  //The return value (exit code) from this subfunction is always 0.  //The return value (exit code) from this subfunction is always 0.
217  //  //
218    
219  #define MODULE_SUBFUNC_CFBRAP  #define MODULE_SUBFUNC_CFBRAP
220    
# Line 374  void SUBFUNC_CFBRAP_pob_dump(struct SUBF Line 374  void SUBFUNC_CFBRAP_pob_dump(struct SUBF
374  /****************************************************************************/  /****************************************************************************/
375  /* INPUT PARAMETER BLOCK MANIPULATION                                       */  /* INPUT PARAMETER BLOCK MANIPULATION                                       */
376  /****************************************************************************/  /****************************************************************************/
377  //Initializes the input parameter block (allocates initial storage).    //Initializes the input parameter block (allocates initial storage).
378  //  //
379  void SUBFUNC_CFBRAP_ipblock_init(struct SUBFUNC_CFBRAP_input_par_struct *arg)  void SUBFUNC_CFBRAP_ipblock_init(struct SUBFUNC_CFBRAP_input_par_struct *arg)
380     {     {
# Line 388  void SUBFUNC_CFBRAP_ipblock_init(struct Line 388  void SUBFUNC_CFBRAP_ipblock_init(struct
388     arg->max_cpu            = 20;     arg->max_cpu            = 20;
389     }     }
390    
391  //Deallocates the input parameter block (deallocates storage).    //Deallocates the input parameter block (deallocates storage).
392  //  //
393  void SUBFUNC_CFBRAP_ipblock_destroy(struct SUBFUNC_CFBRAP_input_par_struct *arg)  void SUBFUNC_CFBRAP_ipblock_destroy(struct SUBFUNC_CFBRAP_input_par_struct *arg)
394     {     {
# Line 406  void SUBFUNC_CFBRAP_ipblock_destroy(stru Line 406  void SUBFUNC_CFBRAP_ipblock_destroy(stru
406  /****************************************************************************/  /****************************************************************************/
407  /* ERROR PATH OUTPUT                                                        */  /* ERROR PATH OUTPUT                                                        */
408  /****************************************************************************/  /****************************************************************************/
409  //Dumps an error code and associated proper information out to the output stream  //Dumps an error code and associated proper information out to the output stream
410  //and returns.  //and returns.
411  //  //
412  int SUBFUNC_CFBRAP_error_dump(int argc, char *argv[])  int SUBFUNC_CFBRAP_error_dump(int argc, char *argv[])
# Line 422  int SUBFUNC_CFBRAP_error_dump(int argc, Line 422  int SUBFUNC_CFBRAP_error_dump(int argc,
422  //and in the event of an error will return 1 and will stuff the output  //and in the event of an error will return 1 and will stuff the output
423  //buffer with only the error code.  //buffer with only the error code.
424  int SUBFUNC_CFBRAP_parse_input_pars(  int SUBFUNC_CFBRAP_parse_input_pars(
425                                      int argc,                                      int argc,
426                                      char *argv[],                                          char *argv[],
427                                      struct SUBFUNC_CFBRAP_input_par_struct *ipb,                                      struct SUBFUNC_CFBRAP_input_par_struct *ipb,
428                                      struct SUBFUNC_CFBRAP_program_output_buffer *pob                                      struct SUBFUNC_CFBRAP_program_output_buffer *pob
429                                      )                                      )
430     {     {
431     char *scratch = NULL;     char *scratch = NULL;
432    
433     //There should be 8 input parameters in addition to the 2 required (the     //There should be 8 input parameters in addition to the 2 required (the
434     //program name plus the subfunction code.  Error out if wrong.     //program name plus the subfunction code.  Error out if wrong.
435     if (argc != 10)     if (argc != 10)
436        {        {
# Line 438  int SUBFUNC_CFBRAP_parse_input_pars( Line 438  int SUBFUNC_CFBRAP_parse_input_pars(
438        return(1);        return(1);
439        }        }
440    
441     //The first input parameter should be the numerator of the rational number to     //The first input parameter should be the numerator of the rational number to
442     //approximate.  We can parse this out and place it into the input parameter     //approximate.  We can parse this out and place it into the input parameter
443     //block.     //block.
444     scratch = malloc(strlen(argv[2]) + 1);     scratch = malloc(strlen(argv[2]) + 1);
# Line 459  int SUBFUNC_CFBRAP_parse_input_pars( Line 459  int SUBFUNC_CFBRAP_parse_input_pars(
459           {           {
460           SUBFUNC_CFBRAP_pob_tack_line(pob, "FNUM");           SUBFUNC_CFBRAP_pob_tack_line(pob, "FNUM");
461           return(1);           return(1);
462           }      }
463        else        else
464           {      {
465           mpz_set_str(ipb->num, scratch, 10);           mpz_set_str(ipb->num, scratch, 10);
466           }           }
467        }        }
468    
469     //The second input parameter should be the denominator of the rational number to     //The second input parameter should be the denominator of the rational number to
470     //approximate.  We can parse this out and place it into the input parameter     //approximate.  We can parse this out and place it into the input parameter
471     //block.     //block.
472     scratch = realloc(scratch, strlen(argv[3]) + 1);     scratch = realloc(scratch, strlen(argv[3]) + 1);
# Line 488  int SUBFUNC_CFBRAP_parse_input_pars( Line 488  int SUBFUNC_CFBRAP_parse_input_pars(
488           {           {
489           SUBFUNC_CFBRAP_pob_tack_line(pob, "FDEN");           SUBFUNC_CFBRAP_pob_tack_line(pob, "FDEN");
490           return(1);           return(1);
491           }      }
492        else        else
493           {      {
494           mpz_set_str(ipb->den, scratch, 10);           mpz_set_str(ipb->den, scratch, 10);
495           }           }
496        }        }
# Line 516  int SUBFUNC_CFBRAP_parse_input_pars( Line 516  int SUBFUNC_CFBRAP_parse_input_pars(
516           {           {
517           SUBFUNC_CFBRAP_pob_tack_line(pob, "FNUMMAX");           SUBFUNC_CFBRAP_pob_tack_line(pob, "FNUMMAX");
518           return(1);           return(1);
519           }      }
520        else        else
521           {      {
522           mpz_set_str(ipb->num_max, scratch, 10);           mpz_set_str(ipb->num_max, scratch, 10);
523           }           }
524        }        }
# Line 544  int SUBFUNC_CFBRAP_parse_input_pars( Line 544  int SUBFUNC_CFBRAP_parse_input_pars(
544           {           {
545           SUBFUNC_CFBRAP_pob_tack_line(pob, "FDENMAX");           SUBFUNC_CFBRAP_pob_tack_line(pob, "FDENMAX");
546           return(1);           return(1);
547           }      }
548        else        else
549           {      {
550           mpz_set_str(ipb->den_max, scratch, 10);           mpz_set_str(ipb->den_max, scratch, 10);
551           }           }
552        }        }
# Line 572  int SUBFUNC_CFBRAP_parse_input_pars( Line 572  int SUBFUNC_CFBRAP_parse_input_pars(
572           {           {
573           SUBFUNC_CFBRAP_pob_tack_line(pob, "FDENMAX");           SUBFUNC_CFBRAP_pob_tack_line(pob, "FDENMAX");
574           return(1);           return(1);
575           }      }
576        else        else
577           {      {
578           mpz_set_str(ipb->den_max, scratch, 10);           mpz_set_str(ipb->den_max, scratch, 10);
579           }           }
580        }        }
# Line 609  int SUBFUNC_CFBRAP_main(int argc, char * Line 609  int SUBFUNC_CFBRAP_main(int argc, char *
609    
610     struct SUBFUNC_CFBRAP_program_output_buffer pob;     struct SUBFUNC_CFBRAP_program_output_buffer pob;
611     //The program output.  Output is buffered because there are some lines     //The program output.  Output is buffered because there are some lines
612     //early that point to later lines.     //early that point to later lines.
613    
614     //Scratch structure.     //Scratch structure.
615     char *scratchstr = NULL;     char *scratchstr = NULL;
# Line 663  int SUBFUNC_CFBRAP_main(int argc, char * Line 663  int SUBFUNC_CFBRAP_main(int argc, char *
663        sprintf(buf, "%d", pob.nlines);        sprintf(buf, "%d", pob.nlines);
664        SUBFUNC_CFBRAP_pob_modify_line(&pob, 2, buf);        SUBFUNC_CFBRAP_pob_modify_line(&pob, 2, buf);
665        }        }
666      
667    
668    
669     error_return:     error_return:
# Line 679  int SUBFUNC_CFBRAP_main(int argc, char * Line 679  int SUBFUNC_CFBRAP_main(int argc, char *
679    
680     //Always return 0.     //Always return 0.
681     return(0);     return(0);
682     }     }
683    
684  //********************************************************************************  //********************************************************************************
685  // End of SUBFUNC_CFBRAP.C.  // End of SUBFUNC_CFBRAP.C.

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

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25