Name

complex<float> template specialization — Single-precision complex number

Synopsis

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

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

explicit complex (const complex<double>& z)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 constructors are 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.