complex - STL C++

pow()

Declaration

complex<X> pow(const complex<X>& kqrBase, const complex<X>& kqrExponent);

Description

This is the friend function pow() for complex numbers. It returns the complex number kqrBase to the power kqrExponent. The overloaded versions support the real number parameter type and integers. The formula for the complex number z that is returned is

z = base^exponent.

Header Include

#include <complex>

Overloads

complex<X> pow(const complex<X>& kqrBase, int iExponent);

complex<X> pow(const X& kxrBase, const complex<X>& kqrExponent);

complex<X> pow(const complex<X>& kqrBase, const X& kxrExponent);

Example

#include <complex>
#include <iostream>

int main()
{
	using namespace std;

	// Create two complex numbers
	complex<double> qZ1(2.0, 4.0);
	complex<double> qZ2(1.3, 5.1);
	cout << "Complex Number 1 : "<< qZ1 << endl;
	cout << "Complex Number 2 : "<< qZ2 << endl;

	// Try each version of the pow() function
	double dReal = 3.14;
	int iInt = 2;
	cout << "Complex base and exponent: " << pow(qZ1, qZ2) << endl;
	cout << "Complex base and int exponent: " << pow(qZ1, iInt) << endl;
	cout << "Real base and complex exponent: " << pow(dReal, qZ1) << endl;
	cout << "Complex base and real exponent: " << pow(qZ1, dReal) << endl;

	// Keep the window open
	cin.get();
	return 0;
}

Output

pow() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.