complex Class

The template class describes an object that stores two objects of type Type, one that represents the real part of a complex number and one that represents the imaginary part.

template<class Type> 
   class complex

Remarks

An object of class Type:

  • Has a public default constructor, destructor, copy constructor, and assignment operator with conventional behavior.

  • Can be assigned integer or floating-point values, or type cast to such values with conventional behavior.

  • Defines the arithmetic operators and math functions, as needed, that are defined for the floating-point types with conventional behavior.

In particular, no subtle differences may exist between copy construction and default construction followed by assignment. None of the operations on objects of class Type may throw exceptions.

Explicit specializations of template class complex exist for the three floating-point types. In this implementation, a value of any other type Type is typecast to double for actual calculations, with the double result assigned back to the stored object of type Type.

Constructors

complex

Constructs a complex number with specified real and imaginary parts or as a copy of some other complex number.

Typedefs

value_type

A type that represents the data type used to represent the real and imaginary parts of a complex number.

Member Functions

imag

Extracts the imaginary component of a complex number.

real

Extracts the real component of a complex number.

Operators

operator*=

Multiplies a target complex number by a factor, which may be complex or be the same type as are the real and imaginary parts of the complex number.

operator+=

Adds a number to a target complex number, where the number added may be complex or of the same type as are the real and imaginary parts of the complex number to which it is added.

operator-=

Subtracts a number from a target complex number, where the number subtracted may be complex or of the same type as are the real and imaginary parts of the complex number to which it is added.

operator/=

Divides a target complex number by a divisor, which may be complex or be the same type as are the real and imaginary parts of the complex number.

operator=

Assigns a number to a target complex number, where the number assigned may be complex or of the same type as are the real and imaginary parts of the complex number to which it is being assigned.

Requirements

Header: <complex>

Namespace: std

See Also

Reference

Thread Safety in the C++ Standard Library

Other Resources

complex Members