Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include <u.h>
2
#include <libc.h>
3
 
4
/*
5
 * sinh(arg) returns the hyperbolic sine of its floating-
6
 * point argument.
7
 *
8
 * The exponential function is called for arguments
9
 * greater in magnitude than 0.5.
10
 *
11
 * A series is used for arguments smaller in magnitude than 0.5.
12
 * The coefficients are #2029 from Hart & Cheney. (20.36D)
13
 *
14
 * cosh(arg) is computed from the exponential function for
15
 * all arguments.
16
 */
17
 
18
static	double	p0  = -0.6307673640497716991184787251e+6;
19
static	double	p1  = -0.8991272022039509355398013511e+5;
20
static	double	p2  = -0.2894211355989563807284660366e+4;
21
static	double	p3  = -0.2630563213397497062819489e+2;
22
static	double	q0  = -0.6307673640497716991212077277e+6;
23
static	double	q1   = 0.1521517378790019070696485176e+5;
24
static	double	q2  = -0.173678953558233699533450911e+3;
25
 
26
double
27
sinh(double arg)
28
{
29
	double temp, argsq;
30
	int sign;
31
 
32
	sign = 0;
33
	if(arg < 0) {
34
		arg = -arg;
35
		sign++;
36
	}
37
	if(arg > 21) {
38
		temp = exp(arg)/2;
39
		goto out;
40
	}
41
	if(arg > 0.5) {
42
		temp = (exp(arg) - exp(-arg))/2;
43
		goto out;
44
	}
45
	argsq = arg*arg;
46
	temp = (((p3*argsq+p2)*argsq+p1)*argsq+p0)*arg;
47
	temp /= (((argsq+q2)*argsq+q1)*argsq+q0);
48
out:
49
	if(sign)
50
		temp = -temp;
51
	return temp;
52
}
53
 
54
double
55
cosh(double arg)
56
{
57
	if(arg < 0)
58
		arg = - arg;
59
	if(arg > 21)
60
		return exp(arg)/2;
61
	return (exp(arg) + exp(-arg))/2;
62
}