Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::log(std::complex)

      From cppreference.com
      <cpp‎ |numeric‎ |complex
       
       
       
       
      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

      [edit]Parameters

      z - complex value

      [edit]Return 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.

      [edit]Error handling and special values

      Errors are reported consistent withmath_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))
      • Ifz is(-0,+0), the result is(-∞,π) andFE_DIVBYZERO is raised
      • Ifz is(+0,+0), the result is(-∞,+0) andFE_DIVBYZERO is raised
      • Ifz is(x,+∞) (for any finite x), the result is(+∞,π/2)
      • Ifz is(x,NaN) (for any finite x), the result is(NaN,NaN) andFE_INVALID may be raised
      • Ifz is(-∞,y) (for any finite positive y), the result is(+∞,π)
      • Ifz is(+∞,y) (for any finite positive y), the result is(+∞,+0)
      • Ifz is(-∞,+∞), the result is(+∞,3π/4)
      • Ifz is(+∞,+∞), the result is(+∞,π/4)
      • Ifz is(±∞,NaN), the result is(+∞,NaN)
      • Ifz is(NaN,y) (for any finite y), the result is(NaN,NaN) andFE_INVALID may be raised
      • Ifz is(NaN,+∞), the result is(+∞,NaN)
      • Ifz is(NaN,NaN), the result is(NaN,NaN)

      [edit]Notes

      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.

      [edit]Example

      Run this code
      #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)

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 2597C++98specification mishandles signed zero imaginary partserroneous requirement removed

      [edit]See also

      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]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/numeric/complex/log&oldid=150849"

      [8]ページ先頭

      ©2009-2025 Movatter.jp