www.pudn.com > AudioWave.rar > Complex.cpp


// Complex.cpp: implementation of the CComplex class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "Complex.h" 
#include "math.h" 
 
#ifdef _DEBUG 
#undef THIS_FILE 
static char THIS_FILE[]=__FILE__; 
#define new DEBUG_NEW 
#endif 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
CComplex::CComplex() 
{ 
	m_dReal=m_dImag=0; 
} 
 
CComplex::~CComplex() 
{ 
 
} 
 
CComplex CComplex::operator +(CComplex second) 
{ 
	CComplex first; 
	first.m_dImag=m_dImag+second.m_dImag; 
	first.m_dReal=m_dReal+second.m_dReal; 
	return first; 
} 
 
CComplex CComplex::operator -(CComplex second) 
{ 
	CComplex first; 
	first.m_dImag=m_dImag-second.m_dImag; 
	first.m_dReal=m_dReal-second.m_dReal; 
	return first; 
 
} 
 
CComplex CComplex::operator *(CComplex second) 
{ 
	CComplex first; 
	first.m_dImag=m_dReal*second.m_dImag+m_dImag*second.m_dReal; 
	first.m_dReal=m_dReal*second.m_dReal-m_dImag*second.m_dImag; 
	return first; 
} 
 
CComplex CComplex::operator /(CComplex second) 
{ 
	CComplex first; 
	double module=second.Module(); 
	second.m_dImag=-second.m_dImag; 
	first=(*this)*second; 
	first.m_dImag/=module; 
	first.m_dReal/=module; 
	return first; 
} 
 
double CComplex::Module() 
{ 
	return(double(sqrt(pow(m_dImag,2)+pow(m_dReal,2)))); 
} 
 
CComplex CComplex::operator =(CComplex second) 
{ 
	m_dReal=second.m_dReal; 
	m_dImag=second.m_dImag; 
	return (*this); 
} 
 
CComplex CComplex::operator /(double divb) 
{ 
	m_dReal/=divb; 
	m_dImag/=divb; 
	return(*this); 
} 
 
CComplex CComplex::operator *(double mivb) 
{ 
	m_dReal*=mivb; 
	m_dImag*=mivb; 
	return(*this); 
} 
 
double CComplex::Arg() 
{ 
	return (atan2(m_dReal,m_dImag)); 
}