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

📄 tcomplex.h

📁 编译类_Hss VC版_源代码支持表达式的编译执行,速度超快,支持实数和复数,并附带一个复数函数库你还可以同时找到VB和VC版和Delphi版
💻 H
📖 第 1 页 / 共 2 页
字号:
// TComplex.h: interface for the TComplex class.
// 扩展精度复数类TComplex  2003.3
//////////////////////////////////////////////////////////////////////

#if !defined(HSS_TComplex_H__A57E05A1_BEDC_4A25_81D6_DB59EE1982E6__INCLUDED_)
#define HSS_TComplex_H__A57E05A1_BEDC_4A25_81D6_DB59EE1982E6__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <complex>
#include "Extended.h"

/////////////////////////////////////////////////////
//             扩展精度复数类TComplex             //
//    相当于 std::complex<Extended>,但不完全相同;  //
/////////////////////////////////////////////////////


class TComplex  
{
    #define _ExFloatPtr  tbyte Ptr
    #define _ExFloatByte 16 

    //下面四个成员共占用32字节
protected:
    Extended    _Re;        //实部
private:
    BYTE        tempX_Ex[6];  //占位用(为了数据8字节边界对齐)
protected:
    Extended    _Im;       //虚部
private:
    BYTE        tempY_Ex[6];  //占位用(为了数据8字节边界对齐)
    
public:
	
    typedef Extended  value_type;
    
    //template <class T> Extended real(const T& x)   { return (this->_Re=x); } //实部
    //template <class T> Extended imag(const T& x)   { return (this->_Im=x); } //虚部
    Extended real()	const							{ return this->_Re; } //实部
    Extended imag()	const							{ return this->_Im; } //虚部
    Extended radius() const; //绝对值
    Extended angle()  const; //复角 -PI ~ PI

    TComplex	()									{}	//为了效率这里并没有赋予默认值0
    template <class T> TComplex (const std::complex<T>  & x)   { this->_Re=x.real(); this->_Im=x.imag(); }
    TComplex	(const long double  x)              { this->_Re=x; this->_Im.Fld_0(); }
    TComplex	(const double       x)              { this->_Re=x; this->_Im.Fld_0(); }
    TComplex	(const float        x)              { this->_Re=x; this->_Im.Fld_0(); }
    TComplex	(const __int64      x)              { this->_Re=x; this->_Im.Fld_0(); }
    TComplex	(const int          x)              { this->_Re=x; this->_Im.Fld_0(); }
    TComplex	(const Extended   & x)              { this->_Re=x; this->_Im.Fld_0(); }
    template <class T1,class T2> TComplex	(const T1& re , const T2& im)   { this->_Re=re; this->_Im=im; }
    //TComplex	(const Extended& re , const Extended& im)                     { this->_Re=re; this->_Im=im; }
    TComplex	(const TComplex	& x)              //{ this->_Re=x._Re; this->_Im=x._Im;}
                  { __asm {   push  eax
                              mov   eax,[x]
                              fld   _ExFloatPtr [eax]
                              fld   _ExFloatPtr [eax+_ExFloatByte]
                              mov   eax,this
                              fstp  _ExFloatPtr [eax+_ExFloatByte]
                              fstp  _ExFloatPtr [eax]
	                          pop   eax } }

    operator long double  () const                { return (long double)this->_Re; }
    operator double	      () const                { return (double)this->_Re; }
    operator float	      () const                { return (float)this->_Re; }
    operator __int64      () const                { return (__int64)this->_Re; }
    operator int          () const                { return (int)this->_Re; }
    operator Extended     () const                { return this->_Re; }
    operator std::complex<Extended>() const			{ return std::complex<Extended>(this->_Re,this->_Im); } //使用模板时无效,只好自己展开
		operator std::complex<long double>() const  { return std::complex<long double>((long double)this->_Re,(long double)this->_Im); }
		operator std::complex<double>() const		{ return std::complex<double>((double)this->_Re,(double)this->_Im); }
		operator std::complex<float>() const		{ return std::complex<float>((float)this->_Re,(float)this->_Im); }
		operator std::complex<__int64>() const		{ return std::complex<__int64>((__int64)this->_Re,(__int64)this->_Im); }
		operator std::complex<int>() const			{ return std::complex<int>((int)this->_Re,(int)this->_Im); }

    template <class T> TComplex& operator =(const std::complex<T>  & y) { this->_Re=y.real(); this->_Im=y.imag(); return *this; }
    TComplex& operator =(const long double x)    { this->_Re=x; this->_Im.Fld_0(); return *this; }
    TComplex& operator =(const double      x)    { this->_Re=x; this->_Im.Fld_0(); return *this; }
    TComplex& operator =(const float       x)    { this->_Re=x; this->_Im.Fld_0(); return *this; }
    TComplex& operator =(const __int64     x)    { this->_Re=x; this->_Im.Fld_0(); return *this; }
    TComplex& operator =(const int         x)    { this->_Re=x; this->_Im.Fld_0(); return *this; }
    TComplex& operator =(const Extended  & x)    { this->_Re=x; this->_Im.Fld_0(); return *this; }
    TComplex& operator =(const TComplex & x)    //{ this->_Re=x._Re; this->_Im=x._Im; return *this; }
                  { __asm {   push  eax
                              mov   eax,[x]
                              fld   _ExFloatPtr [eax]
                              fld   _ExFloatPtr [eax+_ExFloatByte]
                              mov   eax,this
                              fstp  _ExFloatPtr [eax+_ExFloatByte]
                              fstp  _ExFloatPtr [eax]
	                          pop   eax } 
                    return *this; }

    friend  const  TComplex	operator-(const TComplex& x)	{ TComplex r(x); r.Chs(); return r;}
    friend  const  TComplex	operator+(const TComplex& x)	{ return x; }

    //一般版本
    template <class T>  TComplex& operator+=(const T  & x)    { this->Add(x); return *this; }
    template <class T>  TComplex& operator-=(const T  & x)    { this->Sub(x); return *this; }
    template <class T>  TComplex& operator*=(const T  & x)    { this->Mul(x); return *this; }
    template <class T>  TComplex& operator/=(const T  & x)    { this->Div(x); return *this; }
    //完全特化版本
    TComplex& operator+=(const TComplex  & x)   { this->_Re+=x._Re; this->_Im+=x._Im; return *this; }
    TComplex& operator-=(const TComplex  & x)   { this->_Re-=x._Re; this->_Im-=x._Im; return *this; }
    TComplex& operator*=(const TComplex  & x)   { this->Mul(x); return *this; }
    TComplex& operator/=(const TComplex  & x)   { this->Div(x); return *this; }

    template <class T> const TComplex operator+(const T& y)   { TComplex rs(*this); return rs+=y;}
    template <class T> const TComplex operator-(const T& y)   { TComplex rs(*this); return rs-=y;}
    template <class T> const TComplex operator*(const T& y)   { TComplex rs(*this); return rs*=y;}
    template <class T> const TComplex operator/(const T& y)   { TComplex rs(*this); return rs/=y;}
    template <class T> bool operator==(const T& y)    { return (this->_Re==y)&&(this->_Im==0); }
    template <class T> bool operator!=(const T& y)    { return (this->_Re!=y)||(this->_Im!=0); }
    template <class T> bool operator==(const std::complex<T>& y)    { return (this->_Re==y.real()) && (this->_Im==y.imag()); }
    template <class T> bool operator!=(const std::complex<T>& y)    { return (this->_Re!=y.real()) || (this->_Im!=y.imag()); }
    bool operator==(const TComplex& y)      { return (this->_Re==y._Re) && (this->_Im==y._Im); }
    bool operator!=(const TComplex& y)      { return (this->_Re!=y._Re) || (this->_Im!=y._Im); }

    template <class T> friend const TComplex operator+(const std::complex<T>& y, const TComplex& x)   { TComplex rs(x); return rs+=y;}
    template <class T> friend const TComplex operator-(const std::complex<T>& y, const TComplex& x)   { TComplex rs(y); return rs-=x;}
    template <class T> friend const TComplex operator*(const std::complex<T>& y, const TComplex& x)   { TComplex rs(x); return rs*=y;}
    template <class T> friend const TComplex operator/(const std::complex<T>& y, const TComplex& x)   { TComplex rs(y); return rs/=x;}
    template <class T> friend bool operator==(const std::complex<T>& y, const TComplex& x)    { return (x._Re==y.real())&&(x._Im==y.imag()); }
    template <class T> friend bool operator!=(const std::complex<T>& y, const TComplex& x)    { return (x._Re!=y.real())||(x._Im!=y.imag()); }

    friend const TComplex operator+(const Extended& y, const TComplex& x)   { TComplex rs(x); return rs+=y;}
    friend const TComplex operator-(const Extended& y, const TComplex& x)   { TComplex rs(y); return rs-=x;}
    friend const TComplex operator*(const Extended& y, const TComplex& x)   { TComplex rs(x); return rs*=y;}
    friend const TComplex operator/(const Extended& y, const TComplex& x)   { TComplex rs(y); return rs/=x;}
    friend bool operator==(const Extended& y, const TComplex& x)    { return (x._Re==y)&&(x._Im==0); }
    friend bool operator!=(const Extended& y, const TComplex& x)    { return (x._Re!=y)||(x._Im!=0); }

    friend const TComplex operator+(const long double & y, const TComplex& x)   { TComplex rs(x); return rs+=y;}
    friend const TComplex operator-(const long double & y, const TComplex& x)   { TComplex rs(y); return rs-=x;}
    friend const TComplex operator*(const long double & y, const TComplex& x)   { TComplex rs(x); return rs*=y;}
    friend const TComplex operator/(const long double & y, const TComplex& x)   { TComplex rs(y); return rs/=x;}
    friend bool operator==(const long double & y, const TComplex& x)    { return (x._Re==y)&&(x._Im==0); }
    friend bool operator!=(const long double & y, const TComplex& x)    { return (x._Re!=y)||(x._Im!=0); }

    friend const TComplex operator+(const double & y, const TComplex& x)   { TComplex rs(x); return rs+=y;}
    friend const TComplex operator-(const double & y, const TComplex& x)   { TComplex rs(y); return rs-=x;}
    friend const TComplex operator*(const double & y, const TComplex& x)   { TComplex rs(x); return rs*=y;}
    friend const TComplex operator/(const double & y, const TComplex& x)   { TComplex rs(y); return rs/=x;}
    friend bool operator==(const double & y, const TComplex& x)    { return (x._Re==y)&&(x._Im==0); }
    friend bool operator!=(const double & y, const TComplex& x)    { return (x._Re!=y)||(x._Im!=0); }

    friend const TComplex operator+(const float & y, const TComplex& x)   { TComplex rs(x); return rs+=y;}
    friend const TComplex operator-(const float & y, const TComplex& x)   { TComplex rs(y); return rs-=x;}
    friend const TComplex operator*(const float & y, const TComplex& x)   { TComplex rs(x); return rs*=y;}
    friend const TComplex operator/(const float & y, const TComplex& x)   { TComplex rs(y); return rs/=x;}
    friend bool operator==(const float & y, const TComplex& x)    { return (x._Re==y)&&(x._Im==0); }
    friend bool operator!=(const float & y, const TComplex& x)    { return (x._Re!=y)||(x._Im!=0); }

    friend const TComplex operator+(const __int64 & y, const TComplex& x)   { TComplex rs(x); return rs+=y;}
    friend const TComplex operator-(const __int64 & y, const TComplex& x)   { TComplex rs(y); return rs-=x;}
    friend const TComplex operator*(const __int64 & y, const TComplex& x)   { TComplex rs(x); return rs*=y;}
    friend const TComplex operator/(const __int64 & y, const TComplex& x)   { TComplex rs(y); return rs/=x;}
    friend bool operator==(const __int64 & y, const TComplex& x)    { return (x._Re==y)&&(x._Im==0); }
    friend bool operator!=(const __int64 & y, const TComplex& x)    { return (x._Re!=y)||(x._Im!=0); }

    friend const TComplex operator+(const int & y, const TComplex& x)   { TComplex rs(x); return rs+=y;}
    friend const TComplex operator-(const int & y, const TComplex& x)   { TComplex rs(y); return rs-=x;}
    friend const TComplex operator*(const int & y, const TComplex& x)   { TComplex rs(x); return rs*=y;}
    friend const TComplex operator/(const int & y, const TComplex& x)   { TComplex rs(y); return rs/=x;}
    friend bool operator==(const int & y, const TComplex& x)    { return (x._Re==y)&&(x._Im==0); }
    friend bool operator!=(const int & y, const TComplex& x)    { return (x._Re!=y)||(x._Im!=0); }

    ////////////////////////////////////////////////////////////////////////////
	
    //极坐标到复数
    void  FromPolar (const Extended & radius,const Extended & angle); 
    //复数到极坐标

⌨️ 快捷键说明

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