all Python 3cmathfunction
cmath.log10()
powers and logarithms
The base-10 logarithm of a complex number. It differs from math.log10 in the result type and in accepting negative numbers.
Syntax
cmath.log10(z)
Precision trap: cmath.log10(1000) gives (2.9999999999999996+0j), while math.log10(1000) is exactly 3.0. So do not turn the result into an int with int(z.real), you would get 2; use round(z.real) or compare with isclose. A negative argument adds an imaginary part of π/ln 10 ≈ 1.364.
Examples
import cmath
import math
z = cmath.log10(1000)
print(z, math.log10(1000)) # → (2.9999999999999996+0j) 3.0
print(int(z.real), round(z.real)) # → 2 3
import cmath
print(cmath.log10(-100)) # → (2+1.3643763538418412j)
See also
Open in the full glossarydocs.python.orgReport an inaccuracy