Changeset View
Changeset View
Standalone View
Standalone View
EvtGenBase/EvtComplex.hh
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | class EvtComplex { | ||||
inline friend EvtComplex conj( const EvtComplex& c ); | inline friend EvtComplex conj( const EvtComplex& c ); | ||||
inline friend double abs( const EvtComplex& c ); | inline friend double abs( const EvtComplex& c ); | ||||
inline friend double abs2( const EvtComplex& c ); | inline friend double abs2( const EvtComplex& c ); | ||||
inline friend double arg( const EvtComplex& c ); | inline friend double arg( const EvtComplex& c ); | ||||
inline friend double real( const EvtComplex& c ); | inline friend double real( const EvtComplex& c ); | ||||
inline friend double imag( const EvtComplex& c ); | inline friend double imag( const EvtComplex& c ); | ||||
inline friend EvtComplex exp( const EvtComplex& c ); | inline friend EvtComplex exp( const EvtComplex& c ); | ||||
friend std::ostream& operator<<( std::ostream& s, const EvtComplex& c ); | friend std::ostream& operator<<( std::ostream& s, const EvtComplex& c ); | ||||
inline friend EvtComplex operator&( const EvtComplex&, const EvtComplex& ); | |||||
inline friend EvtComplex operator|( const EvtComplex&, const EvtComplex& ); | |||||
public: | public: | ||||
EvtComplex() : _rpart( 0.0 ), _ipart( 0.0 ) {} | EvtComplex() : _rpart( 0.0 ), _ipart( 0.0 ) {} | ||||
EvtComplex( double rpart, double ipart = 0.0 ) : | EvtComplex( double rpart, double ipart = 0.0 ) : | ||||
_rpart( rpart ), _ipart( ipart ) | _rpart( rpart ), _ipart( ipart ) | ||||
{ | { | ||||
} | } | ||||
EvtComplex( const EvtComplex& c ) : _rpart( c._rpart ), _ipart( c._ipart ) | EvtComplex( const EvtComplex& c ) : _rpart( c._rpart ), _ipart( c._ipart ) | ||||
{ | { | ||||
} | } | ||||
inline EvtComplex& operator*=( double d ); | inline EvtComplex& operator*=( double d ); | ||||
inline EvtComplex& operator/=( double d ); | inline EvtComplex& operator/=( double d ); | ||||
EvtComplex& operator*=( EvtComplex c ); | inline EvtComplex& operator*=( EvtComplex c ); | ||||
EvtComplex& operator/=( EvtComplex c ); | inline EvtComplex& operator/=( EvtComplex c ); | ||||
inline EvtComplex& operator=( const EvtComplex& c ); | inline EvtComplex& operator=( const EvtComplex& c ); | ||||
inline EvtComplex& operator+=( const EvtComplex& c ); | inline EvtComplex& operator+=( const EvtComplex& c ); | ||||
inline EvtComplex& operator-=( const EvtComplex& c ); | inline EvtComplex& operator-=( const EvtComplex& c ); | ||||
inline EvtComplex& operator+=( double d ); | inline EvtComplex& operator+=( double d ); | ||||
inline EvtComplex& operator-=( double d ); | inline EvtComplex& operator-=( double d ); | ||||
inline int operator==( const EvtComplex c ); | inline int operator==( const EvtComplex c ); | ||||
inline int operator!=( const EvtComplex c ); | inline int operator!=( const EvtComplex c ); | ||||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
EvtComplex operator*( const EvtComplex& c1, const EvtComplex& c2 ) | EvtComplex operator*( const EvtComplex& c1, const EvtComplex& c2 ) | ||||
{ | { | ||||
return EvtComplex( c1._rpart * c2._rpart - c1._ipart * c2._ipart, | return EvtComplex( c1._rpart * c2._rpart - c1._ipart * c2._ipart, | ||||
c1._rpart * c2._ipart + c1._ipart * c2._rpart ); | c1._rpart * c2._ipart + c1._ipart * c2._rpart ); | ||||
} | } | ||||
// conj(c1)*c2 -- don't forget that the operators "&" and "|" has | |||||
// priority less than the arithmetic operations -- explicit brackets | |||||
// around are necessary! | |||||
EvtComplex operator&( const EvtComplex& c1, const EvtComplex& c2 ) | |||||
{ | |||||
return EvtComplex( c1._rpart * c2._rpart + c1._ipart * c2._ipart, | |||||
c1._rpart * c2._ipart - c1._ipart * c2._rpart ); | |||||
} | |||||
// c1*conj(c2) | |||||
EvtComplex operator|( const EvtComplex& c1, const EvtComplex& c2 ) | |||||
{ | |||||
return EvtComplex( c1._rpart * c2._rpart + c1._ipart * c2._ipart, | |||||
c1._ipart * c2._rpart - c1._rpart * c2._ipart ); | |||||
} | |||||
EvtComplex operator-( const EvtComplex& c1, const EvtComplex& c2 ) | EvtComplex operator-( const EvtComplex& c1, const EvtComplex& c2 ) | ||||
{ | { | ||||
return EvtComplex( c1._rpart - c2._rpart, c1._ipart - c2._ipart ); | return EvtComplex( c1._rpart - c2._rpart, c1._ipart - c2._ipart ); | ||||
} | } | ||||
EvtComplex operator+( const EvtComplex& c1, const EvtComplex& c2 ) | EvtComplex operator+( const EvtComplex& c1, const EvtComplex& c2 ) | ||||
{ | { | ||||
return EvtComplex( c1._rpart + c2._rpart, c1._ipart + c2._ipart ); | return EvtComplex( c1._rpart + c2._rpart, c1._ipart + c2._ipart ); | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | double imag( const EvtComplex& c ) | ||||
return c._ipart; | return c._ipart; | ||||
} | } | ||||
EvtComplex exp( const EvtComplex& c ) | EvtComplex exp( const EvtComplex& c ) | ||||
{ | { | ||||
return exp( c._rpart ) * EvtComplex( cos( c._ipart ), sin( c._ipart ) ); | return exp( c._rpart ) * EvtComplex( cos( c._ipart ), sin( c._ipart ) ); | ||||
} | } | ||||
inline EvtComplex& EvtComplex::operator*=( EvtComplex c ) | |||||
{ | |||||
double r = _rpart * c._rpart - _ipart * c._ipart; | |||||
double i = _rpart * c._ipart + _ipart * c._rpart; | |||||
_rpart = r; | |||||
_ipart = i; | |||||
return *this; | |||||
} | |||||
inline EvtComplex& EvtComplex::operator/=( EvtComplex c ) | |||||
{ | |||||
double inv = 1.0 / ( c._rpart * c._rpart + c._ipart * c._ipart ); | |||||
double r = inv * ( _rpart * c._rpart + _ipart * c._ipart ); | |||||
double i = inv * ( _ipart * c._rpart - _rpart * c._ipart ); | |||||
_rpart = r; | |||||
_ipart = i; | |||||
return *this; | |||||
} | |||||
#endif | #endif |