Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. /* @(#)w_cosh.c 5.1 93/09/24 */
  3. /*
  4.  * ====================================================
  5.  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  6.  *
  7.  * Developed at SunPro, a Sun Microsystems, Inc. business.
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software is freely granted, provided that this notice
  10.  * is preserved.
  11.  * ====================================================
  12.  */
  13.  
  14. /*
  15.  
  16. FUNCTION
  17.         <<cosh>>, <<coshf>>---hyperbolic cosine
  18.  
  19. ANSI_SYNOPSIS
  20.         #include <math.h>
  21.         double cosh(double <[x]>);
  22.         float coshf(float <[x]>)
  23.  
  24. TRAD_SYNOPSIS
  25.         #include <math.h>
  26.         double cosh(<[x]>)
  27.         double <[x]>;
  28.  
  29.         float coshf(<[x]>)
  30.         float <[x]>;
  31.  
  32. DESCRIPTION
  33.  
  34.         <<cosh>> computes the hyperbolic cosine of the argument <[x]>.
  35.         <<cosh(<[x]>)>> is defined as
  36.         @ifnottex
  37.         . (exp(x) + exp(-x))/2
  38.         @end ifnottex
  39.         @tex
  40.         $${(e^x + e^{-x})} \over 2$$
  41.         @end tex
  42.  
  43.         Angles are specified in radians.  
  44.                
  45.         <<coshf>> is identical, save that it takes and returns <<float>>.
  46.  
  47. RETURNS
  48.         The computed value is returned.  When the correct value would create
  49.         an overflow,  <<cosh>> returns the value <<HUGE_VAL>> with the
  50.         appropriate sign, and the global value <<errno>> is set to <<ERANGE>>.
  51.  
  52.         You can modify error handling for these functions using the
  53.         function <<matherr>>.
  54.  
  55. PORTABILITY
  56.         <<cosh>> is ANSI.  
  57.         <<coshf>> is an extension.
  58.  
  59. QUICKREF
  60.         cosh ansi pure
  61.         coshf - pure
  62. */
  63.  
  64. /*
  65.  * wrapper cosh(x)
  66.  */
  67.  
  68. #include "fdlibm.h"
  69. #include <errno.h>
  70.  
  71. #ifndef _DOUBLE_IS_32BITS
  72.  
  73. #ifdef __STDC__
  74.         double cosh(double x)           /* wrapper cosh */
  75. #else
  76.         double cosh(x)                  /* wrapper cosh */
  77.         double x;
  78. #endif
  79. {
  80. #ifdef _IEEE_LIBM
  81.         return __ieee754_cosh(x);
  82. #else
  83.         double z;
  84.         struct exception exc;
  85.         z = __ieee754_cosh(x);
  86.         if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
  87.         if(fabs(x)>7.10475860073943863426e+02) {       
  88.             /* cosh(finite) overflow */
  89. #ifndef HUGE_VAL
  90. #define HUGE_VAL inf
  91.             double inf = 0.0;
  92.  
  93.             SET_HIGH_WORD(inf,0x7ff00000);      /* set inf to infinite */
  94. #endif
  95.             exc.type = OVERFLOW;
  96.             exc.name = "cosh";
  97.             exc.err = 0;
  98.             exc.arg1 = exc.arg2 = x;
  99.             if (_LIB_VERSION == _SVID_)
  100.                exc.retval = HUGE;
  101.             else
  102.                exc.retval = HUGE_VAL;
  103.             if (_LIB_VERSION == _POSIX_)
  104.                errno = ERANGE;
  105.             else if (!matherr(&exc)) {
  106.                errno = ERANGE;
  107.             }
  108.             if (exc.err != 0)
  109.                errno = exc.err;
  110.             return exc.retval;
  111.         } else
  112.             return z;
  113. #endif
  114. }
  115.  
  116. #endif /* defined(_DOUBLE_IS_32BITS) */
  117.