home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 344_02 / sinx.c < prev    next >
Text File  |  1990-02-21  |  1KB  |  38 lines

  1. /*
  2. HEADER:        ;
  3. TITLE:          Sin(x) series approximation;
  4. VERSION:    1.0;
  5.  
  6. DESCRIPTION:    Function to demonstrate how a Taylor series expansion of
  7.         sin(x) may be implemented.  Convergence is fast and
  8.         arguments are accepted in degrees.  Large arguments accepted.;
  9.  
  10. KEYWORDS:       Sin(x), math functions, approximations;
  11. SYSTEM:        MSDOS 1.x, 2.x, 3.x;
  12. FILENAME:    SINX;
  13. WARNINGS:       None ;
  14.  
  15. SEE-ALSO:    LNX, EXP, IFAC, ABS_VAL,MATHCLUD.FUN;
  16. AUTHORS:    Dr. Ronald J. Terry;
  17. COMPILERS:    Turbo C 2.0;
  18. */
  19.  
  20. #include "mathclud.fun"
  21.  
  22. double sinx(double sinarg)
  23. {
  24.      double sum=0.0,s1=100.0,xval,radtodeg=3.14159265358979/180;
  25.      int k=0,oddeven=1;
  26.      sinarg = ((sinarg/360)-(int)(sinarg/360))*360.0; /*  convert to  */
  27.      sinarg = sinarg*radtodeg;           /*  radians and scale input  */
  28.      for(;;)
  29.      {
  30.        sum = sum + oddeven*Intpwr(sinarg,2*k+1)/Ifac(2*k+1);
  31.        oddeven = oddeven*(-1);
  32.        k++;                                        /* sum series */
  33.        if(Abs_val(s1-sum)<=1e-10)
  34.      break;
  35.        s1 = sum;
  36.      }
  37.      return (sum);
  38. }