34 TComplex(): fRe(0), fIm(0) {}
35 TComplex(Double_t re, Double_t im=0, Bool_t polar=kFALSE);
36 virtual ~TComplex() {}
39 static TComplex I() {
return TComplex(0,1);}
40 static TComplex One() {
return TComplex(1,0);}
43 Double_t Re()
const {
return fRe;}
44 Double_t Im()
const {
return fIm;}
45 Double_t Rho()
const {
return TMath::Sqrt(fRe*fRe+fIm*fIm);}
46 Double_t Rho2()
const {
return fRe*fRe+fIm*fIm;}
47 Double_t Theta()
const {
return (fIm||fRe)?TMath::ATan2(fIm,fRe):0;}
48 TComplex operator()(Double_t x, Double_t y, Bool_t polar=kFALSE)
49 {
if (polar) { fRe = x*TMath::Cos(y); fIm = x*TMath::Sin(y); }
50 else { fRe = x; fIm = y; }
return *
this; }
53 TComplex operator *(
const TComplex & c)
const
54 {
return TComplex(fRe*c.fRe-fIm*c.fIm,fRe*c.fIm+fIm*c.fRe);}
55 TComplex operator +(
const TComplex & c)
const
56 {
return TComplex(fRe+c.fRe, fIm+c.fIm);}
57 TComplex operator /(
const TComplex & c)
const
58 {
return TComplex(fRe*c.fRe+fIm*c.fIm,-fRe*c.fIm+fIm*c.fRe)/c.Rho2();}
59 TComplex operator -(
const TComplex & c)
const
60 {
return TComplex(fRe-c.fRe, fIm-c.fIm);}
62 TComplex operator *=(
const TComplex & c)
63 {
return ((*
this) = (*
this) * c);}
64 TComplex operator +=(
const TComplex & c)
65 {
return ((*
this) = (*
this) + c);}
66 TComplex operator /=(
const TComplex & c)
67 {
return ((*
this) = (*
this) / c);}
68 TComplex operator -=(
const TComplex & c)
69 {
return ((*
this) = (*
this) - c);}
72 {
return TComplex(-fRe,-fIm);}
77 TComplex operator *(Double_t c)
const
78 {
return TComplex(fRe*c,fIm*c);}
79 TComplex operator +(Double_t c)
const
80 {
return TComplex(fRe+c, fIm);}
81 TComplex operator /(Double_t c)
const
82 {
return TComplex(fRe/c,fIm/c);}
83 TComplex operator -(Double_t c)
const
84 {
return TComplex(fRe-c, fIm);}
87 friend TComplex operator *(Double_t d,
const TComplex & c)
88 {
return TComplex(d*c.fRe,d*c.fIm);}
89 friend TComplex operator +(Double_t d,
const TComplex & c)
90 {
return TComplex(d+c.fRe, c.fIm);}
91 friend TComplex operator /(Double_t d,
const TComplex & c)
92 {
return TComplex(d*c.fRe,-d*c.fIm)/c.Rho2();}
93 friend TComplex operator -(Double_t d,
const TComplex & c)
94 {
return TComplex(d-c.fRe, -c.fIm);}
97 operator Double_t ()
const {
return fRe;}
98 operator Float_t ()
const {
return static_cast<Float_t
>(fRe);}
99 operator Int_t ()
const {
return static_cast<Int_t
>(fRe);}
102 static TComplex Sqrt(
const TComplex &c)
103 {
return TComplex(TMath::Sqrt(c.Rho()),0.5*c.Theta(),kTRUE);}
105 static TComplex Exp(
const TComplex &c)
106 {
return TComplex(TMath::Exp(c.fRe),c.fIm,kTRUE);}
107 static TComplex Log(
const TComplex &c)
108 {
return TComplex(0.5*TMath::Log(c.Rho2()),c.Theta());}
109 static TComplex Log2(
const TComplex &c)
110 {
return Log(c)/TMath::Log(2);}
111 static TComplex Log10(
const TComplex &c)
112 {
return Log(c)/TMath::Log(10);}
114 static TComplex Sin(
const TComplex &c)
115 {
return TComplex(TMath::Sin(c.fRe)*TMath::CosH(c.fIm),
116 TMath::Cos(c.fRe)*TMath::SinH(c.fIm));}
117 static TComplex Cos(
const TComplex &c)
118 {
return TComplex(TMath::Cos(c.fRe)*TMath::CosH(c.fIm),
119 -TMath::Sin(c.fRe)*TMath::SinH(c.fIm));}
120 static TComplex Tan(
const TComplex &c)
121 {TComplex cc=Cos(c);
return Sin(c)*Conjugate(cc)/cc.Rho2();}
123 static TComplex ASin(
const TComplex &c)
124 {
return -I()*Log(I()*c+TMath::Sign(1.,c.Im())*Sqrt(1.-c*c));}
125 static TComplex ACos(
const TComplex &c)
126 {
return -I()*Log(c+TMath::Sign(1.,c.Im())*Sqrt(c*c-1.));}
127 static TComplex ATan(
const TComplex &c)
128 {
return -0.5*I()*Log((1.+I()*c)/(1.-I()*c));}
130 static TComplex SinH(
const TComplex &c)
131 {
return TComplex(TMath::SinH(c.fRe)*TMath::Cos(c.fIm),
132 TMath::CosH(c.fRe)*TMath::Sin(c.fIm));}
133 static TComplex CosH(
const TComplex &c)
134 {
return TComplex(TMath::CosH(c.fRe)*TMath::Cos(c.fIm),
135 TMath::SinH(c.fRe)*TMath::Sin(c.fIm));}
136 static TComplex TanH(
const TComplex &c)
137 {TComplex cc=CosH(c);
return SinH(c)*Conjugate(cc)/cc.Rho2();}
139 static TComplex ASinH(
const TComplex &c)
140 {
return Log(c+TMath::Sign(1.,c.Im())*Sqrt(c*c+1.));}
141 static TComplex ACosH(
const TComplex &c)
142 {
return Log(c+TMath::Sign(1.,c.Im())*Sqrt(c*c-1.));}
143 static TComplex ATanH(
const TComplex &c)
144 {
return 0.5*Log((1.+c)/(1.-c));}
146 static Double_t Abs(
const TComplex &c)
149 static TComplex Power(
const TComplex& x,
const TComplex& y)
150 {Double_t lrho=TMath::Log(x.Rho());
151 Double_t theta=x.Theta();
152 return TComplex(TMath::Exp(lrho*y.Re()-theta*y.Im()),
153 lrho*y.Im()+theta*y.Re(),kTRUE);}
154 static TComplex Power(
const TComplex& x, Double_t y)
155 {
return TComplex(TMath::Power(x.Rho(),y),x.Theta()*y,kTRUE);}
156 static TComplex Power(Double_t x,
const TComplex& y)
157 {Double_t lrho=TMath::Log(TMath::Abs(x));
158 Double_t theta=(x>0)?0:TMath::Pi();
159 return TComplex(TMath::Exp(lrho*y.Re()-theta*y.Im()),
160 lrho*y.Im()+theta*y.Re(),kTRUE);}
161 static TComplex Power(
const TComplex& x, Int_t y)
162 {
return TComplex(TMath::Power(x.Rho(),y),x.Theta()*y,kTRUE);}
164 static Int_t Finite(
const TComplex& c)
165 {
return TMath::Min(TMath::Finite(c.Re()),TMath::Finite(c.Im()));}
166 static Int_t IsNaN(
const TComplex& c)
167 {
return TMath::IsNaN(c.Re()) || TMath::IsNaN(c.Im());}
169 static TComplex Min(
const TComplex &a,
const TComplex &b)
170 {
return a.Rho()<=b.Rho()?a:b;}
171 static TComplex Max(
const TComplex &a,
const TComplex &b)
172 {
return a.Rho()>=b.Rho()?a:b;}
173 static TComplex Normalize(
const TComplex &c)
174 {
return TComplex(1.,c.Theta(),kTRUE);}
175 static TComplex Conjugate(
const TComplex &c)
176 {
return TComplex(c.Re(),-c.Im());}
177 static TComplex Range(
const TComplex &lb,
const TComplex &ub,
const TComplex &c)
178 {
return Max(lb,Min(c,ub));}
181 friend std::ostream& operator<<(std::ostream& out,
const TComplex& c);
182 friend std::istream& operator>>(std::istream& in, TComplex& c);
188 std::string printValue(TComplex *c);