at_wini also needs a pci_reserve() for the pci compatability device, if
[minix3.git] / lib / math / tanh.c
blobea29c61b679a8a27291864063f71302535075c17
1 /*
2 * (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 * See the copyright notice in the ACK home directory, in the file "Copyright".
5 * Author: Ceriel J.H. Jacobs
6 */
7 /* $Header$ */
9 #include <float.h>
10 #include <math.h>
11 #include <errno.h>
12 #include "localmath.h"
14 double
15 tanh(double x)
17 /* Algorithm and coefficients from:
18 "Software manual for the elementary functions"
19 by W.J. Cody and W. Waite, Prentice-Hall, 1980
22 static double p[] = {
23 -0.16134119023996228053e+4,
24 -0.99225929672236083313e+2,
25 -0.96437492777225469787e+0
27 static double q[] = {
28 0.48402357071988688686e+4,
29 0.22337720718962312926e+4,
30 0.11274474380534949335e+3,
31 1.0
33 int negative = x < 0;
35 if (__IsNan(x)) {
36 errno = EDOM;
37 return x;
39 if (negative) x = -x;
41 if (x >= 0.5*M_LN_MAX_D) {
42 x = 1.0;
44 #define LN3D2 0.54930614433405484570e+0 /* ln(3)/2 */
45 else if (x > LN3D2) {
46 x = 0.5 - 1.0/(exp(x+x)+1.0);
47 x += x;
49 else {
50 /* ??? avoid underflow ??? */
51 double g = x*x;
52 x += x * g * POLYNOM2(g, p)/POLYNOM3(g, q);
54 return negative ? -x : x;