std::log(std::complex)(3)
hey bestie!! welcome to std::log(std::complex)(3) from the C++ Standard Libary manual β this is the C++ standard library page and it's honestly giving main-character math energy π
β¨
π NAME π
std::log(std::complex) β std::log(std::complex)
β¨ Synopsis β¨
Defined in header <complex>
template< class T >
std::complex<T> log( const std::complex<T>& z );
Computes the complex natural (base e) logarithm of a complex value z with a branch cut along the negative real axis. π
π«Ά Parameters π«Ά
zβ complex value
π Return value π
If no errors occur, the complex natural logarithm of z is returned, in the range of a strip in the interval [βiΟ, +iΟ] along the imaginary axis and mathematically unbounded along the real axis.
π¨ Error handling and special values π¨
Errors are reported consistent with math_errhandling.
If the implementation supports IEEE floating-point arithmetic:
- The function is continuous onto the branch cut taking into account the sign of imaginary part
std::log(std::conj(z)) == std::conj(std::log(z))- If
zis(-0,+0), the result is(-β,Ο)andFE_DIVBYZEROis raised - If
zis(+0,+0), the result is(-β,+0)andFE_DIVBYZEROis raised - If
zis(x,+β)(for any finitex), the result is(+β,Ο/2) - If
zis(x,NaN)(for any finitex), the result is(NaN,NaN)andFE_INVALIDmay be raised - If
zis(-β,y)(for any finite positivey), the result is(+β,Ο) - If
zis(+β,y)(for any finite positivey), the result is(+β,+0) - If
zis(-β,+β), the result is(+β,3Ο/4) - If
zis(+β,+β), the result is(+β,Ο/4) - If
zis(Β±β,NaN), the result is(+β,NaN) - If
zis(NaN,y)(for any finitey), the result is(NaN,NaN)andFE_INVALIDmay be raised - If
zis(NaN,+β), the result is(+β,NaN) - If
zis(NaN,NaN), the result is(NaN,NaN)
πΈ Notes πΈ
The natural logarithm of a complex number z with polar coordinate components (r,ΞΈ) equals ln r + i(ΞΈ+2nΟ), with the principal value ln r + iΞΈ.
The semantics of this function are intended to be consistent with the C function clog.
π¦ Example π¦
// Run this code
#include <cmath>
#include <complex>
#include <iostream>
int main()
{
std::complex<double> z {0.0, 1.0}; // r = 1, ΞΈ = pi / 2
std::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 / 4
std::cout << "4 * log" << z2 << " = " << 4.0 * std::log(z2) << '\n';
std::complex<double> z3 {-1.0, 0.0}; // r = 1, ΞΈ = pi
std::cout << "log" << z3 << " = " << std::log(z3) << '\n';
std::complex<double> z4 {-1.0, -0.0}; // the other side of the cut
std::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)
π Defect reports π
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
- DR:
LWG 2597β Applied to:C++98β Behavior as published: specification mishandles signed zero imaginary parts β Correct behavior: erroneous requirement removed
π See also π
log10(std::complex)β complex common logarithm with the branch cuts along the negative real axis (function template)exp(std::complex)β complex base e exponential (function template)log,logf,loglβ computes natural (base e) logarithm (({\small\ln{x}})ln(x)) (function) (C++11) (C++11)log(std::valarray)β applies the functionstd::logto each element of valarray (function template)- C documentation for
clog
okay that's the whole page π«Ά β sourced from http://cppreference.com, dated 2024.06.10, and it's the std::log(std::complex)(3) page. periodt. π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms