/* ---------------------------------------------------------------------------- | _COMPLEX.HPP Defines a class for _COMPLEX numbers ,both floating point and long. */ #include #include #include "globals.h" #ifndef __COMPLEX_ #define __COMPLEX_ class _COMPLEX; //_COMPLEX operator * ( double lhs ,_COMPLEX &rhs ); class _COMPLEX { public: double m_X ; double m_Y ; public: _COMPLEX ( void ) { m_X = 0.0; m_Y = 0.0; } _COMPLEX ( double Factor ) { m_X = Factor; m_Y = 0.0; } _COMPLEX ( double fX ,double fY ){ m_X = fX; m_Y = fY; } _COMPLEX ( _COMPLEX &complex ) { m_X = complex.m_X; m_Y = complex.m_Y; } _COMPLEX ( _COMPLEX *complex ) { m_X = complex->m_X; m_Y = complex->m_Y; } _COMPLEX operator += ( _COMPLEX &rhs ) { this-> m_X += rhs.m_X; this-> m_Y += rhs.m_Y; return *this; } _COMPLEX operator + ( _COMPLEX &rhs ) { _COMPLEX temp( this ); return _COMPLEX( temp += rhs ); } _COMPLEX operator -= ( _COMPLEX &rhs ) { this-> m_X -= rhs.m_X; this-> m_Y -= rhs.m_Y; return *this; } _COMPLEX operator - ( _COMPLEX &rhs ) { _COMPLEX temp( this ); return _COMPLEX( temp -= rhs ); } _COMPLEX operator - ( void ) { _COMPLEX temp; return _COMPLEX( temp -= *this ); } _COMPLEX operator *= ( _COMPLEX &rhs ) { _COMPLEX temp( this ); this-> m_X = temp.m_X*rhs.m_X - temp.m_Y*rhs.m_Y; this-> m_Y = temp.m_X*rhs.m_Y + temp.m_Y*rhs.m_X; return *this; } _COMPLEX operator *= ( double rhs ) { this-> m_X *= rhs; this-> m_Y *= rhs; return *this; } _COMPLEX operator * ( double rhs ) { return _COMPLEX( rhs*this->m_X ,rhs*this->m_Y ); } _COMPLEX operator * ( _COMPLEX &rhs ) { _COMPLEX temp( this ); return _COMPLEX( temp *= rhs ); } friend _COMPLEX operator * ( double lhs ,_COMPLEX rhs ); _COMPLEX operator /= ( double rhs ) { this-> m_X /= rhs; this-> m_Y /= rhs; return *this; } _COMPLEX operator /= ( _COMPLEX &rhs ); _COMPLEX operator / ( double rhs ) { return _COMPLEX( this->m_X / rhs ,this-> m_Y / rhs ); } _COMPLEX operator / ( _COMPLEX &rhs ) { _COMPLEX temp(this); return _COMPLEX( temp /= rhs ); } friend _COMPLEX operator / ( double lhs ,_COMPLEX rhs ); _COMPLEX operator ~ ( void ) { return _COMPLEX( this-> m_X ,-this-> m_Y ); } int operator == ( _COMPLEX &rhs ) { return (this-> m_X == rhs.m_X) && (this-> m_Y == rhs.m_Y); } int operator != ( _COMPLEX &rhs ) { return (this-> m_X != rhs.m_X) || (this-> m_Y != rhs.m_Y); } double Re ( void ) { return m_X; } double Im ( void ) { return m_Y; } double Mag ( void ) { return (double)sqrt( m_X*m_X + m_Y*m_Y ); } double Phase ( void ) { double phs = atan2( m_Y ,m_X ); phs = phs < 0 ? _2PI + phs : phs; return phs; } void Show ( void ); }; #endif