home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols000 / vol082 / sin.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1984-04-29  |  941 b   |  58 lines

  1. extern
  2. function sin ( x : real ): real;
  3.  
  4. const
  5. pi = 3.1415926535897;
  6. two_pi = 6.2831853071796;
  7.  
  8. var
  9. i : integer;
  10.  
  11. procedure compute_sin;
  12. var
  13. result,result2,f,exclam,x2,power : real;
  14. odd1,i : integer;
  15.  
  16.  
  17. begin (* compute_sin *)
  18. x2:=sqr(x);
  19. power:=x*x2;
  20. odd1:=-1;
  21. i:=0;
  22. result:=x;
  23. exclam:=6.0;
  24. f:=3.0;
  25.  
  26. repeat
  27.   result2:=result;
  28.   if odd1 = 1 then
  29.     result := result + (power/exclam)
  30.   else
  31.     result := result - (power/exclam);
  32.   power:=power*x2;
  33.   odd1:=-odd1;
  34. f:=f+2.0;
  35. exclam := f * (f-1.0) * exclam;
  36.   i:=i+1;
  37.   if i > 5 then
  38.     begin
  39.     i:=0;
  40.     if abs(result-result2) < (1e-12*result) then
  41.       result2:=result;
  42.     end;
  43. until result = result2;
  44.  
  45. sin:=result;
  46. end; (* compute_sin *)
  47.  
  48. begin (* sin *)
  49. if (x=0.0) or (x=pi) or (x=two_pi) then sin:=0.0 else
  50. begin
  51. while x < 0.0 do x:=x+two_pi;
  52. while x > two_pi do x:=x-two_pi;
  53.  
  54. compute_sin;
  55.  
  56. end; (* else *)
  57. end; (* sin *).
  58.