home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 105_01 / ctrig.doc < prev    next >
Text File  |  1984-06-05  |  4KB  |  210 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.                       NOTES ON TRIG FUNCTIONS FOR BDS - C
  8.  
  9.  
  10.                                   Introduction
  11.  
  12.  
  13.       These trig functions were developed so that I could do some auxiliary work
  14.  
  15. on scaling and curve generation for a graphics package I'm now doing in BDS-C.
  16.  
  17. They seem to work OK in my setup which is now:  
  18.  
  19.        o  Altair 8800b, 64K CPM 2.2 BDS-C vers 1.42 
  20.  
  21.        o  Tarbell SSSD 4 8 inch disk 
  22.  
  23.        o  Scion Microangelo 
  24.  
  25.        o  LSI ADM3A 
  26.  
  27. This package was developed by:  
  28.  
  29. L. C. Calhoun PE 
  30.  
  31. 257 South Broadway 
  32.  
  33. Lebanon, Ohio 45036 
  34.  
  35. <513> 932-4541/433-7510 
  36.  
  37.  
  38.  
  39.       These programs are written in BDS-C using the floating point package
  40.  
  41. modified to add truncation and magnitude functions.  This package is called
  42.  
  43. "FLOATXT".  The following functions are mechanized:  
  44.  
  45.      char *sine(result,angle) 
  46.  
  47.      char *result, *angle;   /* usual [5] char arrays for fp */ 
  48.  
  49.           The angle input argument is in radians, within the bounds of the
  50.  
  51.           floating point variable.  The function returns the pointer to the
  52.  
  53.           result.  
  54.  
  55.      char *cosine(result,angle) 
  56.  
  57.      char *result, *angle;   /* as with sine */ 
  58.  
  59.           Identical to the sine 
  60.  
  61.      char *tangent(result,angle) 
  62.  
  63.  
  64.  
  65.  
  66.                                         1
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.      char *result, *angle;    /*as with sine */ 
  77.  
  78.      char *arctan(angle,datum) 
  79.  
  80.      char *angle, *datum;    
  81.  
  82.           This returns the angle in radians.  Error conditions, such as too
  83.  
  84.           small or large a datum return "end value" angles.  There is no
  85.  
  86.           over/underflow indication.  Also returns pointer to result.  
  87.  
  88.      char *degtorad(rad, deg) 
  89.  
  90.      char *rad, *deg; 
  91.  
  92.           Converts an angle in degrees to an angle in radians, for use with the
  93.  
  94.           main functions.  Also returns pointer to result.  
  95.  
  96.      char *radtodeg(deg, rad) 
  97.  
  98.      char *deg, *rad; 
  99.  
  100.           Yep, inverse of degtorad Also returns pointer to result.  
  101.  
  102.                                      Method
  103.  
  104.  
  105.       The methods used are outlined in "Functional Approximations" by Fred
  106.  
  107. Ruckdeschel; page 34 ff in BYTE for November 1978.  Note the corrections in the
  108.  
  109. January 1979 issue.  A number of references are given in that article, and are
  110.  
  111. recommended reading.  The following service functions are used:  
  112.  
  113.      char *sinev(result,angle) 
  114.  
  115.      char *result, *angle; 
  116.  
  117.           This is used for both sine and cosine, with the angle reduced to the
  118.  
  119.           range from - pi/2 to + pi/2.  Also returns pointer to result.  
  120.  
  121.      char *atanev(angle,result) 
  122.  
  123.      char *angle, *result; 
  124.  
  125.           This is used for the arctangent evaluation after it is checked for end
  126.  
  127.           value and mid value conditions.  Returns result in radians, in the
  128.  
  129.           range from 0 (almost) to pi/2 for input arguments between 0 (almost)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.                                         2
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.           and infinity (almost).  Also returns pointer to result.  
  146.  
  147.  
  148.  
  149.       A number of checks are made for very large and very small data, to protect
  150.  
  151. the evaluation from the underflow and overflow failures of the floating point
  152.  
  153. package.  I have used TESTTRIG to evaluate over a wide range of variables, and I
  154.  
  155. think! I got all the gotchas.  It looks as though the package has (except at
  156.  
  157. infinity) about an absolute accuracy of .00001.  You will note that I use the
  158.  
  159. properties of the floating point numbers to do magnitude and sign checks.  Lots
  160.  
  161. faster than using fpcomp().  There is another program included, COEFSET, which I
  162.  
  163. used to derive the five decimal equivalents for the constant terms in the series
  164.  
  165. evaluations, etc.  It appears much faster to use initb() to store floating point
  166.  
  167. constants than to use *atof().  
  168.  
  169.  
  170.  
  171.                         Components of the CTRIG Package
  172.        1. CTRIG.DOC             This documentation file 
  173.  
  174.        2. CTRIG.C               Source for trig package 
  175.  
  176.        3. COEFSET.C             Source for coeficient determing program 
  177.  
  178.        4. TRIGTEST.C            Source for trig function testing program 
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.                                         3
  205.  
  206.  
  207.  
  208. d sign checks.  Lots
  209.  
  210.             faster than u