|
|
1.1 root 1:
2: #include "complex.h"
3: #include "const.h"
4:
5: complex cos(complex z)
6: /*
7: The cosine of z: cos(z)=cosh(iz).
8: */
9: {
10: complex y(-z.im, z.re);
11: return cosh(y);
12: }
13:
14:
15:
16: complex cosh(complex z)
17: /*
18: The complex hyperbolic cosine of z
19: */
20: {
21: double cosh_x, sinh_x, cos_y, sin_y;
22:
23: #define COSH_GOOD 1e7
24: #define COSH_HUGE 1e38
25:
26: if (z.re > MAX_EXPONENT) {
27: complex_error(C_COSH_RE, z.re);
28: cosh_x = sinh_x = COSH_HUGE;
29: }
30: else if (z.re < MIN_EXPONENT) {
31: complex_error(C_COSH_RE, z.re);
32: cosh_x = COSH_HUGE;
33: sinh_x = -COSH_HUGE;
34: }
35: else {
36: double pos_exp = exp(z.re);
37: double neg_exp = 1/pos_exp;
38: cosh_x = (pos_exp + neg_exp)/2;
39: sinh_x = (pos_exp - neg_exp)/2;
40: }
41:
42: if (ABS(z.im) > COSH_GOOD) {
43: complex_error(C_COSH_IM, z.im);
44: cos_y = sin_y = 0;
45: }
46: else {
47: cos_y = cos(z.im);
48: sin_y = sin(z.im);
49: }
50:
51: return complex(cos_y*cosh_x, sin_y*sinh_x);
52: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.