Common mathematical functions | |||||||||||||||||||||||||||||||
Mathematical special functions(C++17) | |||||||||||||||||||||||||||||||
Mathematical constants(C++20) | |||||||||||||||||||||||||||||||
Basic linear algebra algorithms(C++26) | |||||||||||||||||||||||||||||||
Data-parallel types (SIMD)(C++26) | |||||||||||||||||||||||||||||||
Floating-point environment(C++11) | |||||||||||||||||||||||||||||||
Complex numbers | |||||||||||||||||||||||||||||||
Numeric array (valarray ) | |||||||||||||||||||||||||||||||
Pseudo-random number generation | |||||||||||||||||||||||||||||||
Bit manipulation(C++20) | |||||||||||||||||||||||||||||||
Saturation arithmetic(C++26) | |||||||||||||||||||||||||||||||
Factor operations | |||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||
Interpolations | |||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||
Generic numeric operations | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||
C-style checked integer arithmetic | |||||||||||||||||||||||||||||||
|
Defined in header <complex> | ||
template<class T> std::complex<T> log(conststd::complex<T>& z); | ||
Computes complexnatural (basee) logarithm of a complex valuez with a branch cut along the negative real axis.
Contents |
z | - | complex value |
If no errors occur, the complex natural logarithm ofz is returned, in the range of a strip in the interval[−iπ, +iπ] along the imaginary axis and mathematically unbounded along the real axis.
Errors are reported consistent withmath_errhandling.
If the implementation supports IEEE floating-point arithmetic,
(-0,+0)
, the result is(-∞,π)
andFE_DIVBYZERO is raised(+0,+0)
, the result is(-∞,+0)
andFE_DIVBYZERO is raised(x,+∞)
(for any finite x), the result is(+∞,π/2)
(x,NaN)
(for any finite x), the result is(NaN,NaN)
andFE_INVALID may be raised(-∞,y)
(for any finite positive y), the result is(+∞,π)
(+∞,y)
(for any finite positive y), the result is(+∞,+0)
(-∞,+∞)
, the result is(+∞,3π/4)
(+∞,+∞)
, the result is(+∞,π/4)
(±∞,NaN)
, the result is(+∞,NaN)
(NaN,y)
(for any finite y), the result is(NaN,NaN)
andFE_INVALID may be raised(NaN,+∞)
, the result is(+∞,NaN)
(NaN,NaN)
, the result is(NaN,NaN)
The natural logarithm of a complex numberz with polar coordinate components(r,θ) equalsln r + i(θ+2nπ), with the principal valueln r + iθ.
The semantics of this function are intended to be consistent with the C functionclog.
#include <cmath>#include <complex>#include <iostream> int main(){std::complex<double> z{0.0,1.0};// r = 1, θ = pi / 2std::cout<<"2 * log"<< z<<" = "<<2.0*std::log(z)<<'\n'; std::complex<double> z2{sqrt(2.0)/2, sqrt(2.0)/2};// r = 1, θ = pi / 4std::cout<<"4 * log"<< z2<<" = "<<4.0*std::log(z2)<<'\n'; std::complex<double> z3{-1.0,0.0};// r = 1, θ = pistd::cout<<"log"<< z3<<" = "<<std::log(z3)<<'\n';std::complex<double> z4{-1.0,-0.0};// the other side of the cutstd::cout<<"log"<< z4<<" (the other side of the cut) = "<<std::log(z4)<<'\n';}
Possible output:
2 * log(0,1) = (0,3.14159)4 * log(0.707107,0.707107) = (0,3.14159)log(-1,0) = (0,3.14159)log(-1,-0) (the other side of the cut) = (0,-3.14159)
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 2597 | C++98 | specification mishandles signed zero imaginary parts | erroneous requirement removed |
complex common logarithm with the branch cuts along the negative real axis (function template)[edit] | |
complex basee exponential (function template)[edit] | |
(C++11)(C++11) | computes natural (basee) logarithm (\({\small\ln{x}}\)ln(x)) (function)[edit] |
applies the functionstd::log to each element of valarray (function template)[edit] | |
C documentation forclog |