Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::pow(std::complex)

      From cppreference.com
      <cpp‎ |numeric‎ |complex
       
       
       
       
      Defined in header<complex>
      template<class T>
      std::complex<T> pow(conststd::complex<T>& x,int y);
      (1)(until C++11)
      template<class T>
      std::complex<T> pow(conststd::complex<T>& x,conststd::complex<T>& y);
      (2)
      template<class T>
      std::complex<T> pow(conststd::complex<T>& x,const T& y);
      (3)
      template<class T>
      std::complex<T> pow(const T& x,conststd::complex<T>& y);
      (4)
      Defined in header<complex>
      (A)
      template<class T1,class T2>

      std::complex</* common-type */>

          pow(conststd::complex<T1>& x,conststd::complex<T2>& y);
      (until C++23)
      template<class T1,class T2>

      std::complex<std::common_type_t<T1, T2>>

          pow(conststd::complex<T1>& x,conststd::complex<T2>& y);
      (since C++23)
      (B)
      template<class T,class NonComplex>

      std::complex</* common-type */>

          pow(conststd::complex<T>& x,const NonComplex& y);
      (until C++23)
      template<class T,class NonComplex>

      std::complex<std::common_type_t<T, NonComplex>>

          pow(conststd::complex<T>& x,const NonComplex& y);
      (since C++23)
      (C)
      template<class T,class NonComplex>

      std::complex</* common-type */>

          pow(const NonComplex& x,conststd::complex<T>& y);
      (until C++23)
      template<class T,class NonComplex>

      std::complex<std::common_type_t<T, NonComplex>>

          pow(const NonComplex& x,conststd::complex<T>& y);
      (since C++23)
      1-4) Computes complexx raised to a complex powery with a branch cut along the negative real axis for the first argument. Non-complex arguments are treated as complex numbers with positive zero imaginary component.
      A-C) Additional overloads are provided.NonComplex is not a specialization ofstd::complex.
      (since C++11)

      Contents

      [edit]Parameters

      x - base
      y - exponent

      [edit]Return value

      1-4) If no errors occur, the complex powerxy
      , is returned.
      Errors and special cases are handled as if the operation is implemented bystd::exp(y*std::log(x)).
      The result ofstd::pow(0,0) is implementation-defined.
      A-C) Same as(2-4).

      [edit]Notes

      Overload(1) was provided in C++98 to match the extra overloads(2) ofstd::pow. Those overloads were removed by the resolution ofLWG issue 550, and overload(1) was removed by the resolution ofLWG issue 844.

      The additional overloads are not required to be provided exactly as(A-C). They only need to be sufficient to ensure that for their first argumentbase and second argumentexponent:

      Ifbase and/orexponent has typestd::complex<T>:

      • Ifbase and/orexponent has typestd::complex<longdouble> orlongdouble, thenstd::pow(base, exponent) has the same effect asstd::pow(std::complex<longdouble>(base),
                 std::complex<longdouble>(exponent))
        .
      • Otherwise, ifbase and/orexponent has typestd::complex<double>,double, or an integer type, thenstd::pow(base, exponent) has the same effect asstd::pow(std::complex<double>(base),
                 std::complex<double>(exponent))
        .
      • Otherwise, ifbase and/orexponent has typestd::complex<float> orfloat, thenstd::pow(base, exponent) has the same effect asstd::pow(std::complex<float>(base),
                 std::complex<float>(exponent))
        .
      (until C++23)

      If one argument has typestd::complex<T1> and the other argument has typeT2 orstd::complex<T2>, thenstd::pow(base, exponent) has the same effect asstd::pow(std::complex<std::common_type_t<T1, T2>>(base),
               std::complex<std::common_type_t<T1, T2>>(exponent))
      .

      Ifstd::common_type_t<T1, T2> is not well-formed, then the program is ill-formed.

      (since C++23)

      [edit]Example

      Run this code
      #include <complex>#include <iostream> int main(){std::cout<<std::fixed; std::complex<double> z(1.0,2.0);std::cout<<"(1,2)^2 = "<<std::pow(z,2)<<'\n'; std::complex<double> z2(-1.0,0.0);// square root of -1std::cout<<"-1^0.5 = "<<std::pow(z2,0.5)<<'\n'; std::complex<double> z3(-1.0,-0.0);// other side of the cutstd::cout<<"(-1,-0)^0.5 = "<<std::pow(z3,0.5)<<'\n'; std::complex<double> i(0.0,1.0);// i^i = exp(-pi / 2)std::cout<<"i^i = "<<std::pow(i, i)<<'\n';}

      Output:

      (1,2)^2 = (-3.000000,4.000000)-1^0.5 = (0.000000,1.000000)(-1,-0)^0.5 = (0.000000,-1.000000)i^i = (0.207880,0.000000)

      [edit]See also

      complex square root in the range of the right half-plane
      (function template)[edit]
      (C++11)(C++11)
      raises a number to the given power (\(\small{x^y}\)xy)
      (function)[edit]
      applies the functionstd::pow to two valarrays or a valarray and a value
      (function template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/numeric/complex/pow&oldid=152476"

      [8]ページ先頭

      ©2009-2025 Movatter.jp