__complex__() __float__() Python
9.3.1.
Python z z.real z.imag :
z r phi r z phi x z
-
cmath.phase(x)
x (x ) phase(x) math.atan2(x.imag, x.real) [-, ] () x.imag x.imag :
>>> phase(complex(-1.0, 0.0))
3.141592653589793
>>> phase(complex(-1.0, -0.0))
-3.141592653589793
-
cmath.polar(x)
x x r x phi (r, phi) polar(x) (abs(x), phase(x))
-
cmath.rect(r, phi)
r, phi x r * (math.cos(phi) + math.sin(phi)*1j)
9.3.2.
-
cmath.exp(x)
e**x
-
cmath.log(x[, base])
base x base x 0 -
-
cmath.log10(x)
x 10 log()
-
cmath.sqrt(x)
x log()
9.3.3.
-
cmath.acos(x)
x (branch cut) : 1 -1 -
-
cmath.asin(x)
x acos()
-
cmath.atan(x)
x : 1j j -1j -j
-
cmath.cos(x)
x
-
cmath.sin(x)
x
-
cmath.tan(x)
x
9.3.4.
-
cmath.acosh(x)
x 1 -
-
cmath.asinh(x)
x : 1j j -1j -j
-
cmath.atanh(x)
x : 1 -1 -
-
cmath.cosh(x)
x
-
cmath.sinh(x)
x
-
cmath.tanh(x)
x
9.3.5.
-
cmath.isfinite(x)
x True False
-
cmath.isinf(x)
x True False
-
cmath.isnan(x)
x NaN True False
-
cmath.isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0)
a b True False
2
rel_tol a b a b
5% rel_tol=0.05
1e-09 29
rel_tol 0
abs_tol 0abs_tol 0
abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)
IEEE 754 NaNinf-inf IEEE
NaN
inf -inf
PEP 485 A function for testing approximate equality
9.3.6.
-
cmath.pi
()
-
cmath.e
e ()
-
cmath.tau
-
cmath.inf
float('inf')
-
cmath.infj
complex(0.0, float('inf'))
-
cmath.nan
"not a number" (NaN) float('nan')
-
cmath.nanj
NaN complex(0.0, float('nan'))
math math.sqrt(-1) cmath ()
(branch cut) : () :
Kahan, W: Branch cuts for complex elementary functions; or, Much ado about nothingss sign bit. In Iserles, A., and Powell, M. (eds.), The state of the art in numerical analysis. Clarendon Press (1987) pp165211.