aboutsummaryrefslogtreecommitdiff
path: root/src/base/math/tanh.c
blob: 81e428aaa3f112a3c8d9507c804ba96141e8c8b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <u.h>
#include <base.h>

/*
	tanh(arg) computes the hyperbolic tangent of its floating
	point argument.

	sinh and cosh are called except for large arguments, which
	would cause overflow improperly.
 */

double
math·tanh(double arg)
{

	if(arg < 0) {
		arg = -arg;
		if(arg > 21)
			return -1;
		return -math·sinh(arg)/math·cosh(arg);
	}
	if(arg > 21)
		return 1;
	return math·sinh(arg)/math·cosh(arg);
}