home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / math / cephes / ieee / etanh.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-17  |  902 b   |  53 lines

  1. /*                            xtanh.c        */
  2. /* hyperbolic tangent check routine */
  3. /* this subroutine is used by the exponential function routine */
  4. /* by Stephen L. Moshier. */
  5.  
  6.  
  7.  
  8. #include "ehead.h"
  9.  
  10.  
  11. void etanh( x, y )
  12. unsigned short *x, *y;
  13. {
  14. unsigned short e[NE], r[NE], j[NE], xx[NE], m2[NE];
  15. short i, n;
  16. long lj;
  17.  
  18. emov( x, r );
  19. r[NE-1] &= (unsigned short )0x7fff;
  20. if( ecmp(r, eone) >= 0 )
  21.     {
  22. /* tanh(x) = (exp(x) - exp(-x)) / (exp(x) + exp(-x))
  23.  * Note eexp() calls xtanh, but with an argument less than (1 + log 2)/2.
  24.  */
  25.     eexp( r, e );
  26.     ediv( e, eone, r );
  27.     esub( r, e, xx );
  28.     eadd( r, e, j );
  29.     ediv( j, xx, y );
  30.     return;
  31.     }
  32.  
  33. emov( etwo, m2 );
  34. eneg( m2 );
  35.  
  36. n = NBITS/8;    /* Number of terms to do in the continued fraction */
  37. lj = 2 * n + 1;
  38. ltoe( &lj, j );
  39.  
  40. emov( j, e );
  41. emul( x, x, xx );
  42.  
  43. /* continued fraction */
  44. for( i=0; i<n; i++)
  45.     {
  46.     ediv( e, xx, r );
  47.     eadd( m2, j, j );
  48.     eadd( r, j, e );
  49.     }
  50.  
  51. ediv( e, x, y );
  52. }
  53.