tanh.c

Go to the documentation of this file.
00001 /*
00002  * (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
00003  * See the copyright notice in the ACK home directory, in the file "Copyright".
00004  *
00005  * Author: Ceriel J.H. Jacobs
00006  */
00007 /* $Header: /opt/proj/minix/cvsroot/src/lib/math/tanh.c,v 1.1.1.1 2005/04/21 14:56:26 beng Exp $ */
00008 
00009 #include        <float.h>
00010 #include        <math.h>
00011 #include        <errno.h>
00012 #include        "localmath.h"
00013 
00014 double
00015 tanh(double x)
00016 {
00017         /*      Algorithm and coefficients from:
00018                         "Software manual for the elementary functions"
00019                         by W.J. Cody and W. Waite, Prentice-Hall, 1980
00020         */
00021 
00022         static double p[] = {
00023                 -0.16134119023996228053e+4,
00024                 -0.99225929672236083313e+2,
00025                 -0.96437492777225469787e+0
00026         };
00027         static double q[] = {
00028                  0.48402357071988688686e+4,
00029                  0.22337720718962312926e+4,
00030                  0.11274474380534949335e+3,
00031                  1.0
00032         };
00033         int     negative = x < 0;
00034 
00035         if (__IsNan(x)) {
00036                 errno = EDOM;
00037                 return x;
00038         }
00039         if (negative) x = -x;
00040 
00041         if (x >= 0.5*M_LN_MAX_D) {
00042                 x = 1.0;
00043         }
00044 #define LN3D2   0.54930614433405484570e+0       /* ln(3)/2 */
00045         else if (x > LN3D2) {
00046                 x = 0.5 - 1.0/(exp(x+x)+1.0);
00047                 x += x;
00048         }
00049         else {
00050                 /* ??? avoid underflow ??? */
00051                 double g = x*x;
00052                 x += x * g * POLYNOM2(g, p)/POLYNOM3(g, q);
00053         }
00054         return negative ? -x : x;
00055 }

Generated on Fri Apr 14 22:57:26 2006 for minix by  doxygen 1.4.6