Created
August 12, 2014 11:25
-
-
Save hirosof/dc0f2764e686a2cd1a36 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void CHSMathComplex::PowerReal(double RealExp) { | |
if (this->Imag == 0) { | |
this->Real = pow(this->Real, RealExp); | |
} else { | |
double R = 0; | |
double Theta = 0; | |
if (this->Real == 0) { | |
int minusFlag = 0; | |
if (this->Imag < 0) { | |
minusFlag = 1; | |
this->Imag *= -1; | |
} | |
R = log(this->Imag); | |
Theta = RealExp * M_PI / 2.0; | |
if (minusFlag)Theta *= -1; | |
} else { | |
R = log(this->GetRadius()); | |
Theta = RealExp * this->GetArgument(); | |
} | |
double Scala = exp(RealExp * R); | |
this->Real = cos(Theta); | |
this->Imag = sin(Theta); | |
this->ScalarMultiple(Scala); | |
} | |
} | |
void CHSMathComplex::PowerImaginary(double ImagExp) { | |
double Scala = 1; | |
double Theta = 0; | |
if (this->Imag == 0) { | |
if (this->Real >= 0) Theta = ImagExp * log(this->Real); | |
else Theta = ImagExp * log(-1.0 * this->Real); | |
} else if (this->Real == 0) { | |
Scala = ImagExp * M_PI / 2; | |
if (this->Imag > 0) { | |
Theta = ImagExp * log(this->Imag); | |
Scala *= -1; | |
} else { | |
Theta = ImagExp * log(-1.0 * this->Imag); | |
} | |
Scala = exp(Scala); | |
} else { | |
Theta = ImagExp * log(this->GetRadius()); | |
Scala = -ImagExp * this->GetArgument(); | |
Scala = exp(Scala); | |
} | |
this->Real = cos(Theta); | |
this->Imag = sin(Theta); | |
this->ScalarMultiple(Scala); | |
} | |
void CHSMathComplex::Power(double RealExp, double ImagExp) { | |
if (ImagExp) { | |
if (RealExp) { | |
double R = log(this->GetRadius()); | |
double Theta = this->GetArgument(); | |
IHSMathComplex *pBufCmp = new CHSMathComplex(RealExp, ImagExp); | |
pBufCmp->Multiplication(R, Theta); | |
this->Real = cos(pBufCmp->Imag); | |
this->Imag = sin(pBufCmp->Imag); | |
this->ScalarMultiple(exp(pBufCmp->Real)); | |
pBufCmp->Dispose(); | |
} else { | |
this->PowerImaginary(ImagExp); | |
} | |
} else { | |
this->PowerReal(RealExp); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment