forked from mnhrdt/ccmath
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC12-complex
358 lines (235 loc) · 10 KB
/
C12-complex
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
Chapter 12
COMPLEX ARITHMETIC
Summary
The complex arithmetic library contains functions
for:
o Basic arithmetic Operations
o A Library of Elementary Functions
The functions accept and return complex numbers
represented as an ordered pair of doubles.
-------------------------------------------------------------------------------
Notes on Contents
o Basic Arithmetic Operations:
carith ------- perform basic operations of multiplication,
division, addition, subtraction, multiplication
by a real or imaginary number, complex conjugation,
changing the sign, and computing the modulus or
its square.
o Complex Elementary Functions:
csqrt -------- compute the square root.
cexp --------- complex exponent function.
clog --------- complex natural logarithm.
ctrig -------- complex trigonometric functions sine, cosine and
tangent.
citrg -------- complex inverse trigonometric functions, on their
principal branches.
chypb -------- complex hyperbolic functions sinh, cosh, and tanh.
cihyp -------- complex inverse hyperbolic functions, on their
principal branches.
-------------------------------------------------------------------------------
General Technical Comments
Complex arithmetic is supported by functions implementing the basic
operations and a library of elementary transcendental functions. The basic
form of a complex number is
z = (re) + i*(im) ,
with both the real (re) and imaginary parts (im) taking double precision real
values.
Conventions selected for the elementary functions that have branch cuts
in the complex z-plane conform to standards for principal branches recommended
in reference [a].
References
[a]. W. Kahan, "Branch Cuts for Elementary Functions," in
"The State of the Art in Numerical Analysis," edited
by A. Iserles and M. J. D. Powell, Oxford Univ. Press,
1987, pp. 165.
_______________________________________________________________________________
FUNCTION SYNOPSES
-------------------------------------------------------------------------------
The header files complex.h (listed below) and ccmath.h define a complex
variable and contain declarations of the library functions.
complex.h
#ifndef CPX
struct complex {double re,im;};
typedef struct complex Cpx;
#define CPX 1
#endif
#include <math.h>
struct complex cadd(),csub(),cmul(),cdiv();
struct complex crmu(),cimu(),ccng(),cdef();
double cabs(),cnrm();
struct complex csqrt(),cexp(),clog();
struct complex csin(),ccos(),ctan();
struct complex casin(),cacos(),catan();
------------------------------------------------------------------
carith
Perform the basic arithmetic operations on complex variables.
Multiplication c = s * t
struct complex cmul(struct complex s,struct complex t)
s,t = complex arguments
return value: c = s*t
---------------------------------------------------------
Division c = s / t
struct complex cdiv(stuct complex s,struct complex t)
s,t = complex arguments
return value: c = s/t
---------------------------------------------------------
Addition c = s + t
struct complex cadd(struct complex s,struct complex t)
s,t = complex arguments
return value: c = s+t
---------------------------------------------------------
Subtraction c = s - t
struct complex csub(struct complex s,struct complex t)
s,t = complex arguments
return value: c = s-t
----------------------------------------------------------
Multiply by a real a, c = a * z
struct complex crmu(double a,struct complex z)
a = real multiplier
z = complex input
return value: c = a*z
-----------------------------------------------------------
Multiply by an imaginary number i, c = i * z
struct complex cimu(double i,struct complex z)
i = imaginary multiplier
z = complex input
return value: c = i*z
------------------------------------------------------------
Take the complex conjugate c = z*
struct complex ccng(struct complex z)
struct complex z;
z = complex input
return value: c = z*
-----------------------------------------------------
Initialize a complex number c = r + i*s
struct complex cdef(double r,double s)
r = real part of number
s = imaginary part of number
return value: c = r+i*s
------------------------------------------------------
Compute the modulus r = | z |
double cabs(struct complex z)
z = complex input
return value: r = |z| (real)
------------------------------------------------------
Compute the squared modulus r^2 = z * z*
double cnrm(struct complex z)
z = complex input
return value: r2 = z*z* (real)
-------------------------------------------------------------------------------
csqrt
Compute the square root of a complex argument c = sqrt(z).
struct complex csqrt(struct complex z)
z = complex input
return value: f = sqrt(z)
principal branch: z = r exp(i*a) with -pi < a <= pi
f = sqrt(r) exp(i*a/2) .
-----------------------------------------------------------
cexp
cexp
Compute exponent exp(z) of a complex argument.
struct complex cexp(struct complex z)
z = complex input
return value: e = exp(z)
clog
Compute the natural logarithm of a complex argument.
struct complex clog(struct complex z)
z = complex input
return value: f = log(z)
principal branches: e = r exp(i*a) with -pi < a <= pi
f = log(r) + i*a
---------------------------------------------------------------
ctrig
Evaluate the trigonometric functions for a complex argument.
csin
struct complex csin(struct complex z)
z = complex input
return value: fs = sin(z)
ccos
struct complex ccos(struct complex z)
z = complex input
return value: fc = cos(z)
ctan
struct complex ctan(struct complex z)
z = complex input
return value: ft = tan(z)
------------------------------------------------------
citrg
Evaluate the inverse trigonometric functions for complex arguments.
casin
struct complex casin(struct complex z)
z = complex input
return value: f = asin(z)
principal branch: z-plane cuts on real axis 1 to infinity
and -1 to -infinity.
f = r + i*s with -pi/2 <= r < pi/2 for s >= 0
and -pi/2 < r <= pi/2 for s < 0
cacos
struct complex cacos(struct complex z)
z = complex input
return value: f = acos(z)
principal branch: z-plane cuts on real axis 1 to infinity
and -1 to -infinity
f = r + i*s with 0 <= r < pi for s >= 0
and 0 < r <= pi for s < 0
catan
struct complex catan(struct complex z)
z = complex input
return value: f = atan(z)
principal branch: z-plane cuts on imaginary axis i to i*infinity
and -i to -i*infinity
f = r + i*s with -pi/2 < r <= pi/2 for s >= 0
and -pi/2 <= r < pi/2 for s < 0
-------------------------------------------------------------------------------
The complex hyperbolic functions are defined by
cosh(z) = cos(i*z)
acosh(z) = f = log(z + sqrt(z*z -1))
sinh(z) = -i*sin(i*z) asinh(z) = i*asin(-i*z)
tanh(z) = -i*tan(i*z) atanh(z) = i*atan(-i*z)
-------------------------------------------------------------------------------
chypb
Evaluate the hyperbolic functions for complex arguments.
csinh
struct complex csinh(struct complex z)
z = complex input
return value: f = sinh(z)
------------------------------------------------------------
ccosh
struct complex ccosh(struct complex z)
z = complex input
return value: f = cosh(z)
-------------------------------------------------------------
ctanh
struct complex ctanh(struct complex z)
z = complex input
return value: f = tanh(z)
-------------------------------------------------------------------------------
cihyp
Evaluate the inverse hyperbolic functions for complex arguments.
casinh
struct complex casinh(struct complex z)
z = complex input
return value: f = asinh(z)
principal branch: z-plane cuts on imaginary axis i to i*infinity
and -i to -i*infinity
f = r + i*s with -pi/2 < s <= pi/2 for r >= 0
and -pi/2 <= s < pi/2 for r < 0
-------------------------------------------------------------------
cacosh
struct complex cacosh(struct complex z)
z = complex input
return value: f = acosh(z)
principal branch: z-plane cut on real axis 1 to -infinity
f = r + i*s with -pi/2 < s <= pi/2 , r >= 0 for s >= 0 ,
and r > 0 for s < 0
This choice makes acosh(z) single valued on the
real z-axis when z > 1.
----------------------------------------------------------------
catanh
struct complex catanh(struct complex z)
z = complex input
return value: f = atanh(z)
principal branch: z-plane cuts on real axis 1 to infinity and
-1 to -infinity
f = r + i*s with -pi/2 <= s < pi/2 for r >= 0
and -pi/2 < s <= pi/2 for r < 0