@@ -22,91 +22,106 @@ result of the conversion.
2222 support signed zeros the continuity is as specified below.
2323
2424
25- Complex coordinates
26- -------------------
25+ Conversions to and from polar coordinates
26+ -----------------------------------------
2727
28- Complex numbers can be expressed by two important coordinate systems.
29- Python's :class: ` complex ` type uses rectangular coordinates where a number
30- on the complex plain is defined by two floats, the real part and the imaginary
31- part.
28+ A Python complex number `` z `` is stored internally using * rectangular *
29+ or * Cartesian * coordinates. It is completely determined by its * real
30+ part * `` z.real `` and its * imaginary part* `` z.imag ``. In other
31+ words::
3232
33- Definition::
33+ z == z.real + z.imag*1j
3434
35- z = x + 1j * y
35+ *Polar coordinates * give an alternative way to represent a complex
36+ number. In polar coordinates, a complex number *z * is defined by the
37+ modulus *r * and the phase angle *phi *. The modulus *r * is the distance
38+ from *z * to the origin, while the phase *phi * is the counterclockwise
39+ angle from the positive x-axis to the line segment that joins the
40+ origin to *z *.
3641
37- x := real(z)
38- y := imag(z)
42+ The following functions can be used to convert from the native
43+ rectangular coordinates to polar coordinates and back.
44+
45+ .. function :: phase(x)
46+
47+ Return the phase of *x * (also known as the *argument * of *x *), as a
48+ float. ``phase(x) `` is equivalent to ``math.atan2(x.imag,
49+ x.real) ``. The result lies in the range [-π, π], and the branch
50+ cut for this operation lies along the negative real axis,
51+ continuous from above. On systems with support for signed zeros
52+ (which includes most systems in current use), this means that the
53+ sign of the result is the same as the sign of ``x.imag ``, even when
54+ ``x.imag `` is zero::
55+
56+ >>> phase(complex(-1.0, 0.0))
57+ 3.141592653589793
58+ >>> phase(complex(-1.0, -0.0))
59+ -3.141592653589793
3960
40- In engineering the polar coordinate system is popular for complex numbers. In
41- polar coordinates a complex number is defined by the radius *r * and the phase
42- angle *phi *. The radius *r * is the absolute value of the complex, which can be
43- viewed as distance from (0, 0). The radius *r * is always 0 or a positive float.
44- The phase angle *phi * is the counter clockwise angle from the positive x axis,
45- e.g. *1 * has the angle *0 *, *1j * has the angle *π/2 * and *-1 * the angle *-π *.
4661
4762.. note ::
48- While :func: `phase ` and func:`polar ` return *+π * for a negative real they
49- may return *-π * for a complex with a very small negative imaginary
50- part, e.g. *-1-1E-300j *.
5163
64+ The modulus (absolute value) of a complex number *x * can be
65+ computed using the built-in :func: `abs ` function. There is no
66+ separate :mod: `cmath ` module function for this operation.
5267
53- Definition::
5468
55- z = r * exp(1j * phi)
56- z = r * cis(phi)
69+ .. function :: polar(x)
5770
58- r := abs(z) := sqrt(real(z)**2 + imag(z)**2)
59- phi := phase(z) := atan2(imag(z), real(z))
60- cis(phi) := cos(phi) + 1j * sin(phi)
71+ Return the representation of *x * in polar coordinates. Returns a
72+ pair ``(r, phi) `` where *r * is the modulus of *x * and phi is the
73+ phase of *x *. ``polar(x) `` is equivalent to ``(abs(x),
74+ phase(x)) ``.
6175
6276
63- .. function :: phase(x )
77+ .. function :: rect(r, phi )
6478
65- Return phase, also known as the argument, of a complex.
79+ Return the complex number *x * with polar coordinates *r * and *phi *.
80+ Equivalent to ``r * (math.cos(phi) + math.sin(phi)*1j) ``.
6681
6782
68- .. function :: polar(x)
83+ Power and logarithmic functions
84+ -------------------------------
6985
70- Convert a :class: `complex ` from rectangular coordinates to polar
71- coordinates. The function returns a tuple with the two elements
72- *r * and *phi *. *r * is the distance from 0 and *phi * the phase
73- angle.
86+ .. function :: exp(x)
7487
88+ Return the exponential value ``e**x ``.
7589
76- .. function :: rect(r, phi)
7790
78- Convert from polar coordinates to rectangular coordinates and return
79- a :class: `complex `.
91+ .. function :: log(x[, base])
8092
93+ Returns the logarithm of *x * to the given *base *. If the *base * is not
94+ specified, returns the natural logarithm of *x *. There is one branch cut, from 0
95+ along the negative real axis to -∞, continuous from above.
8196
97+ .. versionchanged :: 2.4
98+ *base * argument added.
8299
83- cmath functions
84- ---------------
85100
86- .. function :: acos (x)
101+ .. function :: log10 (x)
87102
88- Return the arc cosine of *x *. There are two branch cuts: One extends right from
89- 1 along the real axis to ∞, continuous from below. The other extends left from
90- -1 along the real axis to -∞, continuous from above.
103+ Return the base-10 logarithm of *x *. This has the same branch cut as
104+ :func: `log `.
91105
92106
93- .. function :: acosh (x)
107+ .. function :: sqrt (x)
94108
95- Return the hyperbolic arc cosine of *x *. There is one branch cut, extending left
96- from 1 along the real axis to -∞, continuous from above.
109+ Return the square root of *x *. This has the same branch cut as :func: `log `.
97110
98111
99- .. function :: asin(x)
112+ Trigonometric functions
113+ -----------------------
100114
101- Return the arc sine of * x *. This has the same branch cuts as :func: ` acos `.
115+ .. function :: acos(x)
102116
117+ Return the arc cosine of *x *. There are two branch cuts: One extends right from
118+ 1 along the real axis to ∞, continuous from below. The other extends left from
119+ -1 along the real axis to -∞, continuous from above.
103120
104- .. function :: asinh(x)
105121
106- Return the hyperbolic arc sine of *x *. There are two branch cuts:
107- One extends from ``1j `` along the imaginary axis to ``∞j ``,
108- continuous from the right. The other extends from ``-1j `` along
109- the imaginary axis to ``-∞j ``, continuous from the left.
122+ .. function :: asin(x)
123+
124+ Return the arc sine of *x *. This has the same branch cuts as :func: `acos `.
110125
111126
112127.. function :: atan(x)
@@ -117,83 +132,82 @@ cmath functions
117132 from the left.
118133
119134
120- .. function :: atanh(x)
121-
122- Return the hyperbolic arc tangent of *x *. There are two branch cuts: One
123- extends from ``1 `` along the real axis to ``∞ ``, continuous from below. The
124- other extends from ``-1 `` along the real axis to ``-∞ ``, continuous from
125- above.
126-
127-
128135.. function :: cos(x)
129136
130137 Return the cosine of *x *.
131138
132139
133- .. function :: cosh(x)
134-
135- Return the hyperbolic cosine of *x *.
140+ .. function :: sin(x)
136141
142+ Return the sine of *x *.
137143
138- .. function :: exp(x)
139-
140- Return the exponential value ``e**x ``.
141144
145+ .. function :: tan(x)
142146
143- .. function :: isinf(x)
147+ Return the tangent of * x *.
144148
145- Return *True * if the real or the imaginary part of x is positive
146- or negative infinity.
147149
150+ Hyperbolic functions
151+ --------------------
148152
149- .. function :: isnan (x)
153+ .. function :: acosh (x)
150154
151- Return *True * if the real or imaginary part of x is not a number (NaN).
155+ Return the hyperbolic arc cosine of *x *. There is one branch cut, extending left
156+ from 1 along the real axis to -∞, continuous from above.
152157
153158
154- .. function :: log(x[, base] )
159+ .. function :: asinh(x )
155160
156- Returns the logarithm of *x * to the given *base *. If the *base * is not
157- specified, returns the natural logarithm of *x *. There is one branch cut, from 0
158- along the negative real axis to -∞, continuous from above.
161+ Return the hyperbolic arc sine of *x *. There are two branch cuts:
162+ One extends from ``1j `` along the imaginary axis to ``∞j ``,
163+ continuous from the right. The other extends from ``-1j `` along
164+ the imaginary axis to ``-∞j ``, continuous from the left.
159165
160166
161- .. function :: log10 (x)
167+ .. function :: atanh (x)
162168
163- Return the base-10 logarithm of *x *. This has the same branch cut as
164- :func: `log `.
169+ Return the hyperbolic arc tangent of *x *. There are two branch cuts: One
170+ extends from ``1 `` along the real axis to ``∞ ``, continuous from below. The
171+ other extends from ``-1 `` along the real axis to ``-∞ ``, continuous from
172+ above.
165173
166174
167- .. function :: sin (x)
175+ .. function :: cosh (x)
168176
169- Return the sine of *x *.
177+ Return the hyperbolic cosine of *x *.
170178
171179
172180.. function :: sinh(x)
173181
174182 Return the hyperbolic sine of *x *.
175183
176184
177- .. function :: sqrt (x)
185+ .. function :: tanh (x)
178186
179- Return the square root of *x *. This has the same branch cut as :func: ` log ` .
187+ Return the hyperbolic tangent of *x *.
180188
181189
182- .. function :: tan(x)
190+ Classification functions
191+ ------------------------
183192
184- Return the tangent of *x *.
193+ .. function :: isinf(x)
194+
195+ Return *True * if the real or the imaginary part of x is positive
196+ or negative infinity.
185197
186198
187- .. function :: tanh(x)
199+ .. function :: isnan(x)
200+
201+ Return *True * if the real or imaginary part of x is not a number (NaN).
188202
189- Return the hyperbolic tangent of *x *.
190203
191- The module also defines two mathematical constants:
204+ Constants
205+ ---------
192206
193207
194208.. data :: pi
195209
196- The mathematical constant *pi *, as a float.
210+ The mathematical constant *π *, as a float.
197211
198212
199213.. data :: e
0 commit comments