Name

complex<double> template specialization — Double-precision complex number

Synopsis

template<> class complex<double> {
public:
  typedef double value_type;
  complex(double re = 0.0, double im = 0.0);
  complex(const complex<float>&);
  explicit complex(const complex<long double>&);
  double real(  ) const;
  double imag(  ) const;
  complex<double>& operator= (double);
  complex<double>& operator+=(double);
  complex<double>& operator-=(double);
  complex<double>& operator*=(double);
  complex<double>& operator/=(double);
  complex<double>& operator=(const complex<double>&);
  template<typename X>
    complex<double>& operator= (const complex<X>&);
  template<typename X>
    complex<double>& operator+=(const complex<X>&);
  template<typename X>
    complex<double>& operator-=(const complex<X>&);
  template<typename X>
    complex<double>& operator*=(const complex<X>&);
  template<typename X>
    complex<double>& operator/=(const complex<X>&);
};

The complex<double> class is a straightforward specialization of the complex class template. It changes the operators to pass double parameters by value instead of by reference, and it adds a new constructor:

explicit complex (const complex<long double>& z)

Constructs a complex number by copying from z. Note that you might lose precision or overflow, so the constructor is explicit.

Get C++ In a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.