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
28typedef 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; }
92inline double fabssqr (
const cplx_t&
a)
93{
return (__real__
a) * (__real__
a) + (__imag__
a) * (__imag__
a); }
99{ hcplx cx(
c);
return -cx; }
108{
return MATH__ sqrt ((__real__
a) * (__real__
a) + (__imag__
a) * (__imag__
a)); }
140inline 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)); }
146inline bool operator < (
const hcplx &
a,
const hcplx &
b)
150inline bool operator > (
const hcplx &
a,
const hcplx &
b)
155inline bool operator < (
const hcplx &
a,
const cplx_t &
b)
159inline bool operator > (
const hcplx &
a,
const cplx_t &
b)
164inline bool operator < (
const cplx_t &
a,
const hcplx &
b)
168inline bool operator > (
const cplx_t &
a,
const hcplx &
b)
171#ifdef NEED_BCPLX_COMP_OP
175inline bool operator < (
const cplx_t &
a,
const cplx_t &
b)
179inline 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);
217inline 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);
230inline cplx_t
expi (
const cplx_base phi)
232 cplx_base tmp = fmod (phi,
pi2);
236inline cplx_t
sqr (
const cplx_t &
c)
243const cplx_t Imag_unit =
CPLXVRI (
double, 0.0, 1.0);
250# include "obsolete/b_cplx_old.h"
STD__ istream & operator>>(STD__ istream &istr, BdMatrix< T > &mat)
STD__ ostream & operator<<(STD__ ostream &ostr, const BdMatrix< T > &mat)
#define NAMESPACE_CPLX_END
#define NAMESPACE_CSTD_END
T imag(const TBCI__ cplx< T > &z)
double fabs(const TBCI__ cplx< T > &c)
cplx< T > expi(const T phi)
cplx< T > dot(const cplx< T > &a, const cplx< T > &b)
TBCI__ cplx< T > exp(const TBCI__ cplx< T > &z)
double fabssqr(const cplx< T > &c)
cplx< T > sqr(const cplx< T > &c)
NAMESPACE_END NAMESPACE_CPLX TBCI__ cplx< T > conj(const TBCI__ cplx< T > &c)
TBCI__ cplx< T > sin(const TBCI__ cplx< T > &z)
NAMESPACE_END NAMESPACE_CSTD TBCI__ cplx< T > sqrt(const TBCI__ cplx< T > &z)
TBCI__ cplx< T > cos(const TBCI__ cplx< T > &z)
cplx< T > operator-(const T a, const cplx< T > &b)
NAMESPACE_CPLX_END NAMESPACE_TBCI TBCI__ cplx< T > polar(const T &r, const T &p)
const unsigned TMatrix< T > const Matrix< T > * a
double atan2(const double, const double)
bool operator<(const CPLX__ complex< T > &a, const CPLX__ complex< T > &b)
NAMESPACE_CSTD_END NAMESPACE_CPLX bool operator>(const CPLX__ complex< T > &a, const CPLX__ complex< T > &b)
defined(NO_NS)
bool operator<=(const CPLX__ complex< T > &a, const CPLX__ complex< T > &b)
bool operator>=(const CPLX__ complex< T > &a, const CPLX__ complex< T > &b)