xref: /plan9/sys/src/ape/lib/ap/math/tanh.c (revision 3e12c5d1bb89fc02707907988834ef147769ddaf)
1 #include <math.h>
2 
3 /*
4 	tanh(arg) computes the hyperbolic tangent of its floating
5 	point argument.
6 
7 	sinh and cosh are called except for large arguments, which
8 	would cause overflow improperly.
9  */
10 
11 double
tanh(double arg)12 tanh(double arg)
13 {
14 
15 	if(arg < 0) {
16 		arg = -arg;
17 		if(arg > 21)
18 			return -1;
19 		return -sinh(arg)/cosh(arg);
20 	}
21 	if(arg > 21)
22 		return 1;
23 	return sinh(arg)/cosh(arg);
24 }
25