-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcosh.cpp
69 lines (58 loc) · 743 Bytes
/
cosh.cpp
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// exp(x) + exp(-x)
// cosh(x) = ----------------
// 2
#include "stdafx.h"
#include "defs.h"
void
eval_cosh(void)
{
push(cadr(p1));
eval();
ycosh();
}
void
ycosh(void)
{
save();
yycosh();
restore();
}
void
yycosh(void)
{
double d;
p1 = pop();
if (car(p1) == symbol(ARCCOSH)) {
push(cadr(p1));
return;
}
if (isdouble(p1)) {
d = cosh(p1->u.d);
if (fabs(d) < 1e-10)
d = 0.0;
push_double(d);
return;
}
if (iszero(p1)) {
push(one);
return;
}
push_symbol(COSH);
push(p1);
list(2);
}
#if SELFTEST
static const char *s[] = {
"cosh(x)",
"cosh(x)",
"cosh(0)",
"1",
"cosh(arccosh(x))",
"x",
};
void
test_cosh(void)
{
test(__FILE__, s, sizeof s / sizeof (char *));
}
#endif