cosh.c 608 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. *
  5. * Author: Ceriel J.H. Jacobs
  6. */
  7. /* $Header$ */
  8. #include <math.h>
  9. #include <errno.h>
  10. extern int errno;
  11. double
  12. cosh(x)
  13. double x;
  14. {
  15. extern double exp();
  16. if (x < 0) {
  17. x = -x;
  18. }
  19. if (x > M_LN_MAX_D) {
  20. /* exp(x) would overflow */
  21. if (x >= M_LN_MAX_D + M_LN2) {
  22. /* not representable */
  23. x = HUGE;
  24. errno = ERANGE;
  25. }
  26. else x = exp (x - M_LN2);
  27. }
  28. else {
  29. double expx = exp(x);
  30. x = 0.5 * (expx + 1.0/expx);
  31. }
  32. return x;
  33. }