Overloaded Complex Operators

The overloaded complex operators consists of:

operator+

Adds to the complex class.

  template<class T> complex<T> operator+
  const complex<T>&, const complex<T>&);
  template<class T> complex<T> operator+
  (const complex<T>&, const T&);
  template<class T> complex<T> operator+
  (const T&, const complex<T>&);
  template<class T> complex<T> operator+
  (const complex<T>&);
  
Remarks

The addition performs a += operation.

Returns the complex class after the addition.

operator-

Subtracts from the complex class.

  template<class T> complex<T> operator- 
  (const complex<T>&, const complex<T>&); 
  template<class T> complex<T> operator-
  (const complex<T>&, const T&);
  template<class T> complex<T> operator-
  (const T&, const complex<T>&);
  template<class T> complex<T> operator-
  (const complex<T>&);
  
Remarks

The subtraction performs a -= operation.

Returns the complex class after the Subtraction.

operator*

Multiplies the complex class.

  template<class T> complex<T> operator* 
  (const complex<T>&, const complex<T>&); 
  template<class T> complex<T> operator*
  (const complex<T>&, const T&);
  template<class T> complex<T> operator*
  (const T&, const complex<T>&);
  
Remarks

The multiplication performs a *= operation.

Returns the complex class after the multiplication.

operator/

Divides from the complex class.

  template<class T> complex<T> operator/ 
  (const complex<T>&, const complex<T>&); 
  template<class T> complex<T> operator/
  (const complex<T>&, const T&);
  template<class T> complex<T> operator/
  (const T&, const complex<T>&);
  
Remarks

The division performs a /= operation.

Returns the complex class after the division.

operator==

A boolean equality comparison.

  template<class T> bool operator== 
  (const complex<T>&, const complex<T>&); 
  template<class T> bool operator==
  (const complex<T>&, const T&);
  template<class T> bool operator==
  (const T&, const complex<T>&);
  
Remarks

Returns true if the real and imaginary components are equal.

operator!=

A boolean non equality comparison.

  template<class T> bool operator!=
  (const complex<T>&, const complex<T>&);
  template<class T> bool operator!=
  (const complex<T>&, const T&);
  template<class T> bool operator!=
  (const T&, const complex<T>&);
  
Remarks

Returns true if the real or the imaginary components are not equal.

operator>>

Extracts a complex type from a stream.

  template<class T, class charT, class traits>
  basic_istream<charT, traits>& operator>>
  (basic_istream<charT, traits>&, complex<T>&);
  
Remarks

Extracts in the form of u, (u), or (u,v) where u is the real part and v is the imaginary part.

Any failure in extraction will set the failbit and result in undefined behavior.

operator<<

Inserts a complex number into a stream.

  template<class T, class charT, class traits>
  basic_ostream<charT, traits>& operator<< 
  (basic_ostream<charT, traits>&,const complex<T>&);