Category : C Source Code
Archive   : CEPHES22.ZIP
Filename : QTANH.C

 
Output of file : QTANH.C contained in archive : CEPHES22.ZIP
/* qtanh.c */
/* hyperbolic tangent check routine */
/* this subroutine is used by the exponential function routine */

/* loop count adjusted for convergence to 9 word mantissa if x <= 2 */

#include "qhead.h"

extern short qone[], qtwo[];

int qtanh( x, y )
short *x, *y;
{
short e[NQ], r[NQ], j[NQ], xx[NQ], m2[NQ];
short i, n;
long lj;

qmov( x, r );
r[0] = 0;
if( qcmp(r, qone) >= 0 )
{
/* tanh(x) = (exp(x) - exp(-x)) / (exp(x) + exp(-x))
* Note qexp() calls qtanh, but with an argument less than (1 + log 2)/2.
*/
qexp( r, e );
qdiv( e, qone, r );
qsub( r, e, xx );
qadd( r, e, j );
qdiv( j, xx, y );
goto done;
}

qmov( qtwo, m2 );
qneg( m2 );

n = NBITS/9; /*10;*/
lj = 2 * n + 1;
ltoq( &lj, j );

/* constant 31:
qmov( qone, j );
j[1] = 040005;
j[3] = 0174000;
*/

qmov( j, e );
qmul( x, x, xx );

/* continued fraction */

/*for( i=0; i<15; i++)*/


for( i=0; i {
qdiv( e, xx, r );
qadd( m2, j, j );
qadd( r, j, e );
}

qdiv( e, x, y );

done:
if( x[0] < 0 )
y[0] = -1;
}


  3 Responses to “Category : C Source Code
Archive   : CEPHES22.ZIP
Filename : QTANH.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/