malloc.3: Clarify that realloc() may move the memory block
[man-pages.git] / man7 / complex.7
blob6c7fcaade3dd454a72f398a3beceede83a198058
1 .\" Copyright 2002 Walter Harms (walter.harms@informatik.uni-oldenburg.de)
2 .\"
3 .\" %%%LICENSE_START(GPL_NOVERSION_ONELINE)
4 .\" Distributed under GPL
5 .\" %%%LICENSE_END
6 .\"
7 .TH COMPLEX 7 2021-03-22 "" "Linux Programmer's Manual"
8 .SH NAME
9 complex \- basics of complex mathematics
10 .SH SYNOPSIS
11 .nf
12 .B #include <complex.h>
13 .fi
14 .SH DESCRIPTION
15 Complex numbers are numbers of the form z = a+b*i, where a and b are
16 real numbers and i = sqrt(\-1), so that i*i = \-1.
17 .PP
18 There are other ways to represent that number.
19 The pair (a,b) of real
20 numbers may be viewed as a point in the plane, given by X- and
21 Y-coordinates.
22 This same point may also be described by giving
23 the pair of real numbers (r,phi), where r is the distance to the origin O,
24 and phi the angle between the X-axis and the line Oz.
25 Now
26 z = r*exp(i*phi) = r*(cos(phi)+i*sin(phi)).
27 .PP
28 The basic operations are defined on z = a+b*i and w = c+d*i as:
29 .TP
30 .B addition: z+w = (a+c) + (b+d)*i
31 .TP
32 .B multiplication: z*w = (a*c \- b*d) + (a*d + b*c)*i
33 .TP
34 .B division: z/w = ((a*c + b*d)/(c*c + d*d)) + ((b*c \- a*d)/(c*c + d*d))*i
35 .PP
36 Nearly all math function have a complex counterpart but there are
37 some complex-only functions.
38 .SH EXAMPLES
39 Your C-compiler can work with complex numbers if it supports the C99 standard.
40 Link with \fI\-lm\fP.
41 The imaginary unit is represented by I.
42 .PP
43 .EX
44 /* check that exp(i * pi) == \-1 */
45 #include <math.h>        /* for atan */
46 #include <stdio.h>
47 #include <complex.h>
49 int
50 main(void)
52     double pi = 4 * atan(1.0);
53     double complex z = cexp(I * pi);
54     printf("%f + %f * i\en", creal(z), cimag(z));
56 .EE
57 .SH SEE ALSO
58 .BR cabs (3),
59 .BR cacos (3),
60 .BR cacosh (3),
61 .BR carg (3),
62 .BR casin (3),
63 .BR casinh (3),
64 .BR catan (3),
65 .BR catanh (3),
66 .BR ccos (3),
67 .BR ccosh (3),
68 .BR cerf (3),
69 .BR cexp (3),
70 .BR cexp2 (3),
71 .BR cimag (3),
72 .BR clog (3),
73 .BR clog10 (3),
74 .BR clog2 (3),
75 .BR conj (3),
76 .BR cpow (3),
77 .BR cproj (3),
78 .BR creal (3),
79 .BR csin (3),
80 .BR csinh (3),
81 .BR csqrt (3),
82 .BR ctan (3),
83 .BR ctanh (3)