⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 std_complex.h

📁 linux下的gcc编译器
💻 H
📖 第 1 页 / 共 2 页
字号:
          return complex<_Tp>(__t, __y < _Tp() ? -__t : __t);        }      else        {          _Tp __t = sqrt(2 * (abs(__z) + abs(__x)));          _Tp __u = __t / 2;          return __x > _Tp()            ? complex<_Tp>(__u, __y / __t)            : complex<_Tp>(abs(__y) / __t, __y < _Tp() ? -__u : __u);        }    }  template<typename _Tp>    inline complex<_Tp>    tan(const complex<_Tp>& __z)    {      return sin(__z) / cos(__z);    }  template<typename _Tp>    inline complex<_Tp>    tanh(const complex<_Tp>& __z)    {      return sinh(__z) / cosh(__z);    }  template<typename _Tp>    inline complex<_Tp>    pow(const complex<_Tp>& __z, int __n)    {      return __pow_helper(__z, __n);    }  template<typename _Tp>    complex<_Tp>    pow(const complex<_Tp>& __x, const _Tp& __y)    {      if (__x.imag() == _Tp())        return pow(__x.real(), __y);      complex<_Tp> __t = log(__x);      return polar(exp(__y * __t.real()), __y * __t.imag());    }  template<typename _Tp>    inline complex<_Tp>    pow(const complex<_Tp>& __x, const complex<_Tp>& __y)    {      return __x == _Tp() ? _Tp() : exp(__y * log(__x));    }  template<typename _Tp>    inline complex<_Tp>    pow(const _Tp& __x, const complex<_Tp>& __y)    {      return __x == _Tp()        ? _Tp()        : polar(pow(__x, __y.real()), __y.imag() * log(__x));    }  // 26.2.3  complex specializations  // complex<float> specialization  template<> class complex<float>  {  public:    typedef float value_type;        complex(float = 0.0f, float = 0.0f);#ifdef _GLIBCPP_BUGGY_COMPLEX    complex(const complex& __z) : _M_value(__z._M_value) { }#endif    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);            // Let's the compiler synthetize the copy and assignment    // operator.  It always does a pretty good job.    // complex& operator= (const complex&);    template<typename _Tp>      complex<float>&operator=(const complex<_Tp>&);    template<typename _Tp>      complex<float>& operator+=(const complex<_Tp>&);    template<class _Tp>      complex<float>& operator-=(const complex<_Tp>&);    template<class _Tp>      complex<float>& operator*=(const complex<_Tp>&);    template<class _Tp>      complex<float>&operator/=(const complex<_Tp>&);  private:    typedef __complex__ float _ComplexT;    _ComplexT _M_value;    complex(_ComplexT __z) : _M_value(__z) { }            friend class complex<double>;    friend class complex<long double>;  };  inline float  complex<float>::real() const  { return __real__ _M_value; }  inline float  complex<float>::imag() const  { return __imag__ _M_value; }  inline  complex<float>::complex(float r, float i)  {    __real__ _M_value = r;    __imag__ _M_value = i;  }  inline complex<float>&  complex<float>::operator=(float __f)  {    __real__ _M_value = __f;    __imag__ _M_value = 0.0f;    return *this;  }  inline complex<float>&  complex<float>::operator+=(float __f)  {    __real__ _M_value += __f;    return *this;  }  inline complex<float>&  complex<float>::operator-=(float __f)  {    __real__ _M_value -= __f;    return *this;  }  inline complex<float>&  complex<float>::operator*=(float __f)  {    _M_value *= __f;    return *this;  }  inline complex<float>&  complex<float>::operator/=(float __f)  {    _M_value /= __f;    return *this;  }  template<typename _Tp>  inline complex<float>&  complex<float>::operator=(const complex<_Tp>& __z)  {    __real__ _M_value = __z.real();    __imag__ _M_value = __z.imag();    return *this;  }  template<typename _Tp>  inline complex<float>&  complex<float>::operator+=(const complex<_Tp>& __z)  {    __real__ _M_value += __z.real();    __imag__ _M_value += __z.imag();    return *this;  }      template<typename _Tp>    inline complex<float>&    complex<float>::operator-=(const complex<_Tp>& __z)    {     __real__ _M_value -= __z.real();     __imag__ _M_value -= __z.imag();     return *this;    }   template<typename _Tp>    inline complex<float>&    complex<float>::operator*=(const complex<_Tp>& __z)    {      _ComplexT __t;      __real__ __t = __z.real();      __imag__ __t = __z.imag();      _M_value *= __t;      return *this;    }  template<typename _Tp>    inline complex<float>&    complex<float>::operator/=(const complex<_Tp>& __z)    {      _ComplexT __t;      __real__ __t = __z.real();      __imag__ __t = __z.imag();      _M_value /= __t;      return *this;    }  // 26.2.3  complex specializations  // complex<double> specialization  template<> class complex<double>  {  public:    typedef double value_type;    complex(double  =0.0, double =0.0);#ifdef _GLIBCPP_BUGGY_COMPLEX    complex(const complex& __z) : _M_value(__z._M_value) { }#endif    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);    // The compiler will synthetize this, efficiently.    // complex& operator= (const complex&);    template<typename _Tp>      complex<double>& operator=(const complex<_Tp>&);    template<typename _Tp>      complex<double>& operator+=(const complex<_Tp>&);    template<typename _Tp>      complex<double>& operator-=(const complex<_Tp>&);    template<typename _Tp>      complex<double>& operator*=(const complex<_Tp>&);    template<typename _Tp>      complex<double>& operator/=(const complex<_Tp>&);  private:    typedef __complex__ double _ComplexT;    _ComplexT _M_value;    complex(_ComplexT __z) : _M_value(__z) { }            friend class complex<float>;    friend class complex<long double>;  };  inline double  complex<double>::real() const  { return __real__ _M_value; }  inline double  complex<double>::imag() const  { return __imag__ _M_value; }  inline  complex<double>::complex(double __r, double __i)  {    __real__ _M_value = __r;    __imag__ _M_value = __i;  }  inline complex<double>&  complex<double>::operator=(double __d)  {    __real__ _M_value = __d;    __imag__ _M_value = 0.0;    return *this;  }  inline complex<double>&  complex<double>::operator+=(double __d)  {    __real__ _M_value += __d;    return *this;  }  inline complex<double>&  complex<double>::operator-=(double __d)  {    __real__ _M_value -= __d;    return *this;  }  inline complex<double>&  complex<double>::operator*=(double __d)  {    _M_value *= __d;    return *this;  }  inline complex<double>&  complex<double>::operator/=(double __d)  {    _M_value /= __d;    return *this;  }  template<typename _Tp>    inline complex<double>&    complex<double>::operator=(const complex<_Tp>& __z)    {      __real__ _M_value = __z.real();      __imag__ _M_value = __z.imag();      return *this;    }      template<typename _Tp>    inline complex<double>&    complex<double>::operator+=(const complex<_Tp>& __z)    {      __real__ _M_value += __z.real();      __imag__ _M_value += __z.imag();      return *this;    }  template<typename _Tp>    inline complex<double>&    complex<double>::operator-=(const complex<_Tp>& __z)    {      __real__ _M_value -= __z.real();      __imag__ _M_value -= __z.imag();      return *this;    }  template<typename _Tp>    inline complex<double>&    complex<double>::operator*=(const complex<_Tp>& __z)    {      _ComplexT __t;      __real__ __t = __z.real();      __imag__ __t = __z.imag();      _M_value *= __t;      return *this;    }  template<typename _Tp>    inline complex<double>&    complex<double>::operator/=(const complex<_Tp>& __z)    {      _ComplexT __t;      __real__ __t = __z.real();      __imag__ __t = __z.imag();      _M_value /= __t;      return *this;    }  // 26.2.3  complex specializations  // complex<long double> specialization  template<> class complex<long double>  {  public:    typedef long double value_type;    complex(long double = 0.0L, long double = 0.0L);#ifdef _GLIBCPP_BUGGY_COMPLEX    complex(const complex& __z) : _M_value(__z._M_value) { }#endif    complex(const complex<float>&);    complex(const complex<double>&);    long double real() const;    long double imag() const;    complex<long double>& operator= (long double);    complex<long double>& operator+= (long double);    complex<long double>& operator-= (long double);    complex<long double>& operator*= (long double);    complex<long double>& operator/= (long double);    // The compiler knows how to do this efficiently    // complex& operator= (const complex&);    template<typename _Tp>      complex<long double>& operator=(const complex<_Tp>&);    template<typename _Tp>      complex<long double>& operator+=(const complex<_Tp>&);    template<typename _Tp>      complex<long double>& operator-=(const complex<_Tp>&);    template<typename _Tp>      complex<long double>& operator*=(const complex<_Tp>&);    template<typename _Tp>      complex<long double>& operator/=(const complex<_Tp>&);  private:    typedef __complex__ long double _ComplexT;    _ComplexT _M_value;    complex(_ComplexT __z) : _M_value(__z) { }    friend class complex<float>;    friend class complex<double>;  };  inline  complex<long double>::complex(long double __r, long double __i)  {    __real__ _M_value = __r;    __imag__ _M_value = __i;  }  inline long double  complex<long double>::real() const  { return __real__ _M_value; }  inline long double  complex<long double>::imag() const  { return __imag__ _M_value; }  inline complex<long double>&     complex<long double>::operator=(long double __r)  {    __real__ _M_value = __r;    __imag__ _M_value = 0.0L;    return *this;  }  inline complex<long double>&  complex<long double>::operator+=(long double __r)  {    __real__ _M_value += __r;    return *this;  }  inline complex<long double>&  complex<long double>::operator-=(long double __r)  {    __real__ _M_value -= __r;    return *this;  }  inline complex<long double>&  complex<long double>::operator*=(long double __r)  {    _M_value *= __r;    return *this;  }  inline complex<long double>&  complex<long double>::operator/=(long double __r)  {    _M_value /= __r;    return *this;  }  template<typename _Tp>    inline complex<long double>&    complex<long double>::operator=(const complex<_Tp>& __z)    {      __real__ _M_value = __z.real();      __imag__ _M_value = __z.imag();      return *this;    }  template<typename _Tp>    inline complex<long double>&    complex<long double>::operator+=(const complex<_Tp>& __z)    {      __real__ _M_value += __z.real();      __imag__ _M_value += __z.imag();      return *this;    }  template<typename _Tp>    inline complex<long double>&    complex<long double>::operator-=(const complex<_Tp>& __z)    {      __real__ _M_value -= __z.real();      __imag__ _M_value -= __z.imag();      return *this;    }      template<typename _Tp>    inline complex<long double>&    complex<long double>::operator*=(const complex<_Tp>& __z)    {      _ComplexT __t;      __real__ __t = __z.real();      __imag__ __t = __z.imag();      _M_value *= __t;      return *this;    }  template<typename _Tp>    inline complex<long double>&    complex<long double>::operator/=(const complex<_Tp>& __z)    {      _ComplexT __t;      __real__ __t = __z.real();      __imag__ __t = __z.imag();      _M_value /= __t;      return *this;    }  // These bits have to be at the end of this file, so that the  // specializations have all been defined.  // ??? No, they have to be there because of compiler limitation at  // inlining.  It suffices that class specializations be defined.  inline  complex<float>::complex(const complex<double>& __z)  : _M_value(_ComplexT(__z._M_value)) { }  inline  complex<float>::complex(const complex<long double>& __z)  : _M_value(_ComplexT(__z._M_value)) { }  inline  complex<double>::complex(const complex<float>& __z)   : _M_value(_ComplexT(__z._M_value)) { }  inline  complex<double>::complex(const complex<long double>& __z)  {    __real__ _M_value = __z.real();    __imag__ _M_value = __z.imag();  }  inline  complex<long double>::complex(const complex<float>& __z)  : _M_value(_ComplexT(__z._M_value)) { }  inline  complex<long double>::complex(const complex<double>& __z)  : _M_value(_ComplexT(__z._M_value)) { }} // namespace std#endif	/* _CPP_COMPLEX */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -