1 #ifndef __CKCOMPLEX_H__
2 #define __CKCOMPLEX_H__
8 typedef fftw_real RealType
;
10 typedef double RealType
;
21 inline ckcomplex(RealType _re
=0., RealType _im
=0.): re(_re
), im(_im
){}
22 // inline ckcomplex(RealType r) {re=r; im=0;}
23 // inline ckcomplex(RealType r,RealType i) {re=r; im=i;}
25 inline ~ckcomplex() {}
27 inline RealType
getMagSqr(void) const {
31 inline ckcomplex
operator+(ckcomplex a
) {
32 return ckcomplex(re
+a
.re
,im
+a
.im
);
36 inline friend ckcomplex
operator-(ckcomplex lhs
, ckcomplex rhs
) {
37 return ckcomplex(lhs
.re
- rhs
.re
, lhs
.im
- rhs
.im
);
40 inline ckcomplex
conj(void) {
41 return ckcomplex(re
, -im
);
44 inline void operator+=(ckcomplex a
) {
49 inline friend ckcomplex
operator*(RealType lhs
, ckcomplex rhs
) {
50 return ckcomplex(rhs
.re
*lhs
, rhs
.im
*lhs
);
53 inline friend ckcomplex
operator/(ckcomplex lhs
, RealType rhs
) {
54 return ckcomplex(lhs
.re
/rhs
, lhs
.im
/rhs
);
57 inline ckcomplex
operator*(RealType a
) {
58 return ckcomplex(re
*a
, im
*a
);
61 inline bool notzero() const { return( (0.0 != re
) ? true : (0.0 != im
)); }
63 inline void operator*=(ckcomplex a
) {
65 treal
= re
* a
.re
- im
* a
.im
;
66 tim
= re
* a
.im
+ im
* a
.re
;
71 inline ckcomplex
operator*(ckcomplex a
) {
72 return ckcomplex( re
* a
.re
- im
* a
.im
, re
* a
.im
+ im
* a
.re
);
76 inline void operator -= (ckcomplex a
) {
77 re
-= a
.re
; im
-= a
.im
;
81 inline ckcomplex
multiplyByi () {
82 return ckcomplex(-im
, re
);
85 inline void * operator new[] (size_t size
){
86 void *buf
= malloc(size
);
90 inline void operator delete[] (void *buf
){
94 inline friend std::ostream
& operator<< (std::ostream
&out
, const ckcomplex
&aNum
) {
95 out
<<"("<<aNum
.re
<<","<<aNum
.im
<<")";
100 typedef ckcomplex
complex;
105 /// Overload std::isfinite for complex numbers. @note: Doesn't seem to be part of the standard
106 inline int isfinite(complex aNum
) { return ( std::isfinite(aNum
.re
) && std::isfinite(aNum
.im
) ); }
108 /// Like std::norm, return the square of the distance from (0,0) in the complex number plane
109 inline RealType
norm(complex aNum
) { return ( aNum
.re
*aNum
.re
+ aNum
.im
*aNum
.im
); }
110 /// Return the distance from (0,0) in the complex plane
111 inline RealType
abs(complex aNum
) { return ( sqrt(norm(aNum
)) ); }