asin.c 567 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * asin(arg) and acos(arg) return the arcsin, arccos,
  3. * respectively of their arguments.
  4. *
  5. * Arctan is called after appropriate range reduction.
  6. */
  7. #include <u.h>
  8. #include <libc.h>
  9. double
  10. asin(double arg)
  11. {
  12. double temp;
  13. int sign;
  14. sign = 0;
  15. if(arg < 0) {
  16. arg = -arg;
  17. sign++;
  18. }
  19. if(arg > 1)
  20. return NaN();
  21. temp = sqrt(1 - arg*arg);
  22. if(arg > 0.7)
  23. temp = PIO2 - atan(temp/arg);
  24. else
  25. temp = atan(arg/temp);
  26. if(sign)
  27. temp = -temp;
  28. return temp;
  29. }
  30. double
  31. acos(double arg)
  32. {
  33. if(arg > 1 || arg < -1)
  34. return NaN();
  35. return PIO2 - asin(arg);
  36. }