Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*                                                      coshl.c
  2.  *
  3.  *      Hyperbolic cosine, long double precision
  4.  *
  5.  *
  6.  *
  7.  * SYNOPSIS:
  8.  *
  9.  * long double x, y, coshl();
  10.  *
  11.  * y = coshl( x );
  12.  *
  13.  *
  14.  *
  15.  * DESCRIPTION:
  16.  *
  17.  * Returns hyperbolic cosine of argument in the range MINLOGL to
  18.  * MAXLOGL.
  19.  *
  20.  * cosh(x)  =  ( exp(x) + exp(-x) )/2.
  21.  *
  22.  *
  23.  *
  24.  * ACCURACY:
  25.  *
  26.  *                      Relative error:
  27.  * arithmetic   domain     # trials      peak         rms
  28.  *    IEEE     +-10000      30000       1.1e-19     2.8e-20
  29.  *
  30.  *
  31.  * ERROR MESSAGES:
  32.  *
  33.  *   message         condition              value returned
  34.  * cosh overflow    |x| > MAXLOGL+LOGE2L      INFINITYL
  35.  *
  36.  *
  37.  */
  38.  
  39. /*
  40. Cephes Math Library Release 2.7:  May, 1998
  41. Copyright 1985, 1991, 1998 by Stephen L. Moshier
  42. */
  43.  
  44. /*
  45. Modified for mingw
  46. 2002-07-22 Danny Smith <dannysmith@users.sourceforge.net>
  47. */
  48.  
  49. #ifdef __MINGW32__
  50. #include "cephes_mconf.h"
  51. #else
  52. #include "mconf.h"
  53. #endif
  54.  
  55. #ifndef _SET_ERRNO
  56. #define _SET_ERRNO(x)
  57. #endif
  58.  
  59.  
  60. #ifndef __MINGW32__
  61. extern long double MAXLOGL, MAXNUML, LOGE2L;
  62. #ifdef ANSIPROT
  63. extern long double expl ( long double );
  64. extern int isnanl ( long double );
  65. #else
  66. long double expl(), isnanl();
  67. #endif
  68. #ifdef INFINITIES
  69. extern long double INFINITYL;
  70. #endif
  71. #ifdef NANS
  72. extern long double NANL;
  73. #endif
  74. #endif /* __MINGW32__ */
  75.  
  76. long double coshl(x)
  77. long double x;
  78. {
  79. long double y;
  80.  
  81. #ifdef NANS
  82. if( isnanl(x) )
  83.         {
  84.         _SET_ERRNO(EDOM);
  85.         return(x);
  86.         }
  87. #endif
  88. if( x < 0 )
  89.         x = -x;
  90. if( x > (MAXLOGL + LOGE2L) )
  91.         {
  92.         mtherr( "coshl", OVERFLOW );
  93.         _SET_ERRNO(ERANGE);
  94. #ifdef INFINITIES
  95.         return( INFINITYL );
  96. #else
  97.         return( MAXNUML );
  98. #endif
  99.         }      
  100. if( x >= (MAXLOGL - LOGE2L) )
  101.         {
  102.         y = expl(0.5L * x);
  103.         y = (0.5L * y) * y;
  104.         return(y);
  105.         }
  106. y = expl(x);
  107. y = 0.5L * (y + 1.0L / y);
  108. return( y );
  109. }
  110.