atn.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. *
  4. * This product is part of the Amsterdam Compiler Kit.
  5. *
  6. * Permission to use, sell, duplicate or disclose this software must be
  7. * obtained in writing. Requests for such permissions may be sent to
  8. *
  9. * Dr. Andrew S. Tanenbaum
  10. * Wiskundig Seminarium
  11. * Vrije Universiteit
  12. * Postbox 7161
  13. * 1007 MC Amsterdam
  14. * The Netherlands
  15. *
  16. */
  17. /* $Header$ */
  18. /* Author: J.W. Stevenson */
  19. /*
  20. floating-point arctangent
  21. atan returns the value of the arctangent of its
  22. argument in the range [-pi/2,pi/2].
  23. there are no error returns.
  24. coefficients are #5077 from Hart & Cheney. (19.56D)
  25. */
  26. static double sq2p1 = 2.414213562373095048802e0;
  27. static double sq2m1 = .414213562373095048802e0;
  28. static double pio2 = 1.570796326794896619231e0;
  29. static double pio4 = .785398163397448309615e0;
  30. static double p4 = .161536412982230228262e2;
  31. static double p3 = .26842548195503973794141e3;
  32. static double p2 = .11530293515404850115428136e4;
  33. static double p1 = .178040631643319697105464587e4;
  34. static double p0 = .89678597403663861959987488e3;
  35. static double q4 = .5895697050844462222791e2;
  36. static double q3 = .536265374031215315104235e3;
  37. static double q2 = .16667838148816337184521798e4;
  38. static double q1 = .207933497444540981287275926e4;
  39. static double q0 = .89678597403663861962481162e3;
  40. /*
  41. xatan evaluates a series valid in the
  42. range [-0.414...,+0.414...].
  43. */
  44. static double
  45. xatan(arg)
  46. double arg;
  47. {
  48. double argsq;
  49. double value;
  50. argsq = arg*arg;
  51. value = ((((p4*argsq + p3)*argsq + p2)*argsq + p1)*argsq + p0);
  52. value = value/(((((argsq + q4)*argsq + q3)*argsq + q2)*argsq + q1)*argsq + q0);
  53. return(value*arg);
  54. }
  55. static double
  56. satan(arg)
  57. double arg;
  58. {
  59. if(arg < sq2m1)
  60. return(xatan(arg));
  61. else if(arg > sq2p1)
  62. return(pio2 - xatan(1/arg));
  63. else
  64. return(pio4 + xatan((arg-1)/(arg+1)));
  65. }
  66. /*
  67. atan makes its argument positive and
  68. calls the inner routine satan.
  69. */
  70. double
  71. _atn(arg)
  72. double arg;
  73. {
  74. if(arg>0)
  75. return(satan(arg));
  76. else
  77. return(-satan(-arg));
  78. }