sinh.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <u.h>
  2. #include <libc.h>
  3. /*
  4. * sinh(arg) returns the hyperbolic sine of its floating-
  5. * point argument.
  6. *
  7. * The exponential function is called for arguments
  8. * greater in magnitude than 0.5.
  9. *
  10. * A series is used for arguments smaller in magnitude than 0.5.
  11. * The coefficients are #2029 from Hart & Cheney. (20.36D)
  12. *
  13. * cosh(arg) is computed from the exponential function for
  14. * all arguments.
  15. */
  16. static double p0 = -0.6307673640497716991184787251e+6;
  17. static double p1 = -0.8991272022039509355398013511e+5;
  18. static double p2 = -0.2894211355989563807284660366e+4;
  19. static double p3 = -0.2630563213397497062819489e+2;
  20. static double q0 = -0.6307673640497716991212077277e+6;
  21. static double q1 = 0.1521517378790019070696485176e+5;
  22. static double q2 = -0.173678953558233699533450911e+3;
  23. double
  24. sinh(double arg)
  25. {
  26. double temp, argsq;
  27. int sign;
  28. sign = 0;
  29. if(arg < 0) {
  30. arg = -arg;
  31. sign++;
  32. }
  33. if(arg > 21) {
  34. temp = exp(arg)/2;
  35. goto out;
  36. }
  37. if(arg > 0.5) {
  38. temp = (exp(arg) - exp(-arg))/2;
  39. goto out;
  40. }
  41. argsq = arg*arg;
  42. temp = (((p3*argsq+p2)*argsq+p1)*argsq+p0)*arg;
  43. temp /= (((argsq+q2)*argsq+q1)*argsq+q0);
  44. out:
  45. if(sign)
  46. temp = -temp;
  47. return temp;
  48. }
  49. double
  50. cosh(double arg)
  51. {
  52. if(arg < 0)
  53. arg = - arg;
  54. if(arg > 21)
  55. return exp(arg)/2;
  56. return (exp(arg) + exp(-arg))/2;
  57. }