名前空間
変種
操作

std::pow(std::complex)

From cppreference.com
< cpp‎ | numeric‎ | complex
 
 
 
 
ヘッダ <complex> で定義
template< class T >
std::complex<T> pow( const std::complex<T>& x, int y );
(1) (C++11まで)
template< class T >
std::complex<T> pow( const std::complex<T>& x, const std::complex<T>& y );
(2)
template< class T >
std::complex<T> pow( const std::complex<T>& x, const T& y );
(3)
template< class T >
std::complex<T> pow( const T& x, const std::complex<T>& y );
(4)
ヘッダ <complex> で定義
(A)
template< class T1, class T2 >

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

    pow( const std::complex<T1>& x, const std::complex<T2>& y );
(C++23まで)
template< class T1, class T2 >

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

    pow( const std::complex<T1>& x, const std::complex<T2>& y );
(C++23から)
(B)
template< class T, class NonComplex >

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

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

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

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

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

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

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

    pow( const NonComplex& x, const std::complex<T>& y );
(C++23から)
1-4) 복소수 x를 복소수 거듭제곱 y로 올립니다. 이때 첫 번째 인수에 대해 음의 실수 축을 따라 분지 절단이 있습니다. 비복소수 인수는 양의 0 허수 부분을 갖는 복소수로 취급됩니다.
A-C) 추가적인 오버로드가 제공됩니다. NonComplexstd::complex의 특수화가 아닙니다.
(C++11以降)

目次

[edit] パラメータ

x - base
y - exponent

[edit] 戻り値

1-4) 오류가 발생하지 않으면, 복소수 거듭제곱 xy
가 반환됩니다.
오류 및 특수 사례는 연산이 std::exp(y * std::log(x))에 의해 구현되는 것처럼 처리됩니다.
std::pow(0, 0)의 결과는 구현 정의입니다.
A-C) (2-4)와 동일합니다.

[edit] 注記

오버로드 (1)은 C++98에서 std::pow의 추가 오버로드 (2)와 일치하도록 제공되었습니다. 해당 오버로드는 LWG 이슈 550의 해결로 제거되었으며, 오버로드 (1)은 LWG 이슈 844의 해결로 제거되었습니다.

추가 오버로드는 (A-C)와 정확히 동일하게 제공될 필요는 없습니다. 이러한 오버로드는 첫 번째 인수 base와 두 번째 인수 exponent에 대해 다음을 보장하기에 충분하기만 하면 됩니다.

만약 base 및/또는 exponentstd::complex<T> 타입이라면

  • 만약 base 및/또는 exponentstd::complex<long double> 또는 long double 타입이라면, std::pow(base, exponent)std::pow(std::complex<long double>(base),
             std::complex<long double>(exponent))
    와 동일한 효과를 갖습니다.
  • 그렇지 않고, 만약 base 및/또는 exponentstd::complex<double>, double, 또는 정수 타입이라면, std::pow(base, exponent)std::pow(std::complex<double>(base),
             std::complex<double>(exponent))
    와 동일한 효과를 갖습니다.
  • 그렇지 않고, 만약 base 및/또는 exponentstd::complex<float> 또는 float 타입이라면, std::pow(base, exponent)std::pow(std::complex<float>(base),
             std::complex<float>(exponent))
    와 동일한 효과를 갖습니다.
(C++23まで)

한 인수가 std::complex<T1> 타입이고 다른 인수가 T2 또는 std::complex<T2> 타입이라면, std::pow(base, exponent)std::pow(std::complex<std::common_type_t<T1, T2>>(base),
         std::complex<std::common_type_t<T1, T2>>(exponent))
와 동일한 효과를 갖습니다.

만약 std::common_type_t<T1, T2>가 잘 정의되지 않았다면, 프로그램은 정의되지 않습니다.

(C++23から)

[edit]

#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 -1
    std::cout << "-1^0.5 = " << std::pow(z2, 0.5) << '\n';
 
    std::complex<double> z3(-1.0, -0.0); // other side of the cut
    std::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';
}

出力

(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] 関連項目

複素数の平方根、右半平面の範囲
(関数テンプレート) [編集]
(C++11)(C++11)
数値を指定されたべき乗に累乗する (xy)
(関数) [編集]
2つのvalarray、またはvalarrayと値に関数std::powを適用する
(function template) [編集]
English 日本語 中文(简体) 中文(繁體)