//---------------------------------------------------------------------------- // EgalTech 2013-2013 //---------------------------------------------------------------------------- // File : Complex.cpp Data : 08.01.14 Versione : 1.5a1 // Contenuto : Implementazione classe dei numeri complessi. // // // // Modifiche : 08.01.14 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "\EgtDev\Include\ENkComplex.h" //---------------------------- Classe Complex --------------------------------- Complex Complex::operator +=( double dVal) { this->re += dVal ; return *this; } //---------------------------------------------------------------------------- Complex Complex::operator +=( Complex& cVal) { this->re += cVal.re; this->im += cVal.im; return *this; } //---------------------------------------------------------------------------- Complex Complex::operator -=( double dVal) { this->re -= dVal ; return *this ; } //---------------------------------------------------------------------------- Complex Complex::operator -=( Complex& cVal) { this->re -= cVal.re ; this->im -= cVal.im ; return *this ; } //---------------------------------------------------------------------------- Complex Complex::operator *=( double dVal) { this->re *= dVal ; this->im *= dVal ; return *this; } //---------------------------------------------------------------------------- Complex Complex::operator /=( double dVal) { double dInv ; dInv = 1.0 / dVal ; this->re *= dInv ; this->im *= dInv ; return *this ; } //---------------------------------------------------------------------------- Complex Complex::operator >>=( int n) { this->re = ldexp( this->re, -n) ; this->im = ldexp( this->im, -n) ; return *this ; } //---------------------------------------------------------------------------- Complex Complex::operator <<=( int n) { this->re = ldexp( this->re, +n) ; this->im = ldexp( this->im, +n) ; return *this ; } //---------------------------------------------------------------------------- Complex Complex::operator *=( Complex& cVal) { return ( *this = *this * cVal) ; } //---------------------------------------------------------------------------- Complex Complex::operator /=( Complex& cVal) { return ( *this *= inv( cVal)) ; } //------------------------------ Functions ----------------------------------- // sqrt for Complex Complex sqrt( Complex& cVal) { Complex z ; // Power 0.5 simple enough double m ; // to do separate, faster // than full exp(0.5*log(z)) // just like reals have their m = mod( cVal) ; // sqrt. Ours gives the one z.re = sqrt( (m + cVal.re) / 2) ; // with -pi/2 < arg <= +pi/2 z.im = sqrt( (m - cVal.re) / 2) ; // Our log interprets arg if ( cVal.im < 0.) // as in range -pi to pi, z.im = - z.im ; // like the atan2 used. return z ; } //---------------------------------------------------------------------------- // log for Complex Complex log( Complex& cVal) { Complex z ; z.re = log( m2( cVal)) / 2 ; z.im = atan2( cVal.im, cVal.re) ; return z ; } //---------------------------------------------------------------------------- Complex exp( Complex& cVal) { Complex ez ; double m ; m = exp( cVal.re) ; ez.re = m * cos( cVal.im) ; ez.im = m * sin( cVal.im) ; return ez ; } //---------------------------------------------------------------------------- Complex cosh( Complex& cVal) { Complex ez ; ez = exp( cVal) ; return ( ( ez + inv(ez)) >> 1) ; } //---------------------------------------------------------------------------- Complex sinh( Complex& cVal) { Complex ez ; ez = exp( cVal) ; return ( ( ez - inv(ez)) >> 1) ; } //---------------------------------------------------------------------------- Complex tanh( Complex& cVal) { Complex e2z ; e2z = exp( cVal << 1) ; return ( ( e2z - 1) / ( e2z + 1)) ; } //---------------------------------------------------------------------------- Complex cos( Complex& cVal) { return cosh( itimes( cVal)) ; } //---------------------------------------------------------------------------- Complex isin( Complex& cVal) { return sinh( itimes( cVal)) ; } //---------------------------------------------------------------------------- Complex sin( Complex& cVal) { return -itimes( isin( cVal)) ; }; //---------------------------------------------------------------------------- Complex itan( Complex& cVal) { return tanh( itimes( cVal)) ; } //---------------------------------------------------------------------------- Complex tan( Complex& cVal) { return -itimes( itan( cVal)) ; } //---------------------------------------------------------------------------- Complex acosh( Complex& cVal) { return log( cVal + sqrt( cVal * cVal - 1)) ; } //---------------------------------------------------------------------------- Complex asinh( Complex& cVal) { return log( cVal + sqrt( cVal * cVal + 1)) ; } //---------------------------------------------------------------------------- Complex atanh( Complex& cVal) { return ( log(( 1 + cVal) / ( 1 - cVal)) >> 1) ; } //---------------------------------------------------------------------------- Complex acos( Complex& cVal) { return -itimes( acosh( cVal)) ; } //---------------------------------------------------------------------------- Complex asin( Complex& cVal) { return -itimes( asinh( itimes( cVal))) ; } //---------------------------------------------------------------------------- Complex atan( Complex& cVal) { return -itimes( atanh( itimes( cVal))) ; }