11 #include "tbci/constants.h"
13 #include "tbci/basics.h"
15 #ifndef HAVE_BUILTIN_CPLX
16 # include "tbci/cplx.h"
19 #ifndef TBCI_BUILTIN_CPLX_H
20 #define TBCI_BUILTIN_CPLX_H
28 typedef CTYP cplx_base;
31 typedef __complex__ CTYP cplx_t;
32 # define CPLX(t) cplx_t
33 # define CPLXR(t,a,r) cplx_t a (r)
34 # define CPLXRI(t,a,r,i) cplx_t a; __real__ a = (r); __imag__ a = (i)
35 # define CPLXC(t,a,c) cplx_t a (c)
36 # define CPLXVRI(t,r,m) ((cplx_t) ((r) + (m) * 1.0i))
40 #define USE_BUILTIN_CPLX 1
55 hcplx (
const hcplx &
c) : cx(c.cx) {}
57 hcplx (
const cplx_base r,
const cplx_base
i = 0) { __real__ cx = r; __imag__ cx =
i; }
61 hcplx (
const cplx_t&
c) : cx(c) {}
65 operator const cplx_t& ()
const {
return cx; }
71 {
return (__real__ cx) * (__real__ cx) + (__imag__ cx) * (__imag__ cx); }
78 const cplx_base&
real ()
const {
return __real__ cx; }
79 const cplx_base&
imag ()
const {
return __imag__ cx; }
81 cplx_base
real ()
const {
return __real__ cx; }
82 cplx_base
imag ()
const {
return __imag__ cx; }
84 cplx_base&
real () {
return __real__ cx; }
85 cplx_base&
imag () {
return __imag__ cx; }
88 { cplx_t r; __real__ r = - __real__ cx; __imag__ r = - __imag__ cx;
return r; }
92 inline double fabssqr (
const cplx_t&
a)
93 {
return (__real__ a) * (__real__
a) + (__imag__ a) * (__imag__
a); }
95 inline double fabssqr (
const TBCI__ hcplx&
c) {
return c.fabssqr(); }
99 { hcplx cx(c);
return -cx; }
108 {
return MATH__ sqrt ((__real__ a) * (__real__ a) + (__imag__ a) * (__imag__ a)); }
125 inline const TBCI__ cplx_base&
real (
const TBCI__ hcplx& c) {
return c.real(); }
126 inline const TBCI__ cplx_base&
imag (
const TBCI__ hcplx& c) {
return c.imag(); }
140 inline cplx_t
dot (
const cplx_t a,
const cplx_t
b)
141 {
return hcplx ((__real__ a) * (__real__ b) + (__imag__ a) * (__imag__ b),
142 (__imag__ a) * (__real__ b) - (__real__ a) * (__imag__ b)); }
144 inline bool operator <= (
const hcplx & a,
const hcplx & b)
146 inline bool operator < (
const hcplx & a,
const hcplx & b)
148 inline bool operator >= (
const hcplx & a,
const hcplx & b)
150 inline bool operator > (
const hcplx & a,
const hcplx & b)
153 inline bool operator <= (
const hcplx & a,
const cplx_t & b)
155 inline bool operator < (
const hcplx & a,
const cplx_t & b)
157 inline bool operator >= (
const hcplx & a,
const cplx_t & b)
159 inline bool operator > (
const hcplx & a,
const cplx_t & b)
162 inline bool operator <= (
const cplx_t & a,
const hcplx & b)
164 inline bool operator < (
const cplx_t & a,
const hcplx & b)
166 inline bool operator >= (
const cplx_t & a,
const hcplx & b)
168 inline bool operator > (
const cplx_t & a,
const hcplx & b)
171 #ifdef NEED_BCPLX_COMP_OP
173 inline bool operator <= (
const cplx_t & a,
const cplx_t & b)
175 inline bool operator < (
const cplx_t & a,
const cplx_t & b)
177 inline bool operator >= (
const cplx_t & a,
const cplx_t & b)
179 inline bool operator > (
const cplx_t & a,
const cplx_t & b)
184 { os <<
"( " << __real__
c;
185 if ((__imag__ c) < 0)
return os <<
" - i " << - __imag__ c <<
" )";
186 else return os <<
" + i " << __imag__ c <<
" )";
192 char s =
'+', b =
'i', bra =
'(';
196 if (bra !=
'(') in.putback(bra);
200 if ((s !=
'+') && (s !=
'-')) in.putback(s);
202 if ((b !=
'i')) in.putback(b);
206 if (s ==
'-') __imag__ c =-
i;
212 if (bra !=
')') in.putback(bra);
217 inline cplx_base
polar (
const cplx_t& c)
221 if (__imag__ c > 0)
return 0.5*
pi;
222 else if (__imag__ c < 0)
return 1.5*
pi;
226 if (__imag__ c >= 0)
return MATH__ atan2 (__imag__ c, __real__ c);
230 inline cplx_t
expi (
const cplx_base phi)
232 cplx_base tmp = fmod (phi,
pi2);
236 inline cplx_t
sqr (
const cplx_t &c)
242 #ifdef NEED_IMAG_UNIT
243 const cplx_t Imag_unit =
CPLXVRI (
double, 0.0, 1.0);
250 # include "obsolete/b_cplx_old.h"
bool operator>=(const CPLX__ complex< T > &a, const CPLX__ complex< T > &b)
cplx< T > operator-(const T a, const cplx< T > &b)
STD__ ostream & operator<<(STD__ ostream &ostr, const BdMatrix< T > &mat)
STD__ istream & operator>>(STD__ istream &istr, BdMatrix< T > &mat)
TBCI__ cplx< T > cos(const TBCI__ cplx< T > &z)
double atan2(const double, const double)
bool operator<(const CPLX__ complex< T > &a, const CPLX__ complex< T > &b)
#define NAMESPACE_CSTD_END
cplx< T > expi(const T phi)
const Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > & z
cplx< T > sqr(const cplx< T > &c)
TBCI__ cplx< T > sin(const TBCI__ cplx< T > &z)
NAMESPACE_CSTD_END NAMESPACE_CPLX bool operator>(const CPLX__ complex< T > &a, const CPLX__ complex< T > &b)
defined(NO_NS)
TBCI__ cplx< T > exp(const TBCI__ cplx< T > &z)
int conj(const int arg)
conj for elementary types
T dot(const T &a1, const T &a2)
#define NAMESPACE_CPLX_END
double fabssqr(const double a)
const unsigned TMatrix< T > const Matrix< T > * a
bool operator<=(const CPLX__ complex< T > &a, const CPLX__ complex< T > &b)
NAMESPACE_CPLX_END NAMESPACE_TBCI TBCI__ cplx< T > polar(const T &r, const T &p)