16 #include "tbci/basics.h"
17 #ifndef TBCI_CPLX_DONT_INCLUDE_CONSTANTS
18 # include "tbci/constants.h"
22 # pragma interface "cplx.h"
26 #if defined(__GNUC__) && defined (USE_BUILTIN_CPLX)
27 # include "tbci/builtin_cplx.h"
31 # define CPLX(t) cplx<t>
32 # define CPLXR(t,a,r) cplx<t> a (r)
33 # define CPLXRI(t,a,r,i) cplx<t> a (r,i)
34 # define CPLXC(t,a,c) cplx<t> a (c)
35 # define CPLXVRI(t,r,i) (cplx<t>(r,i))
38 #if !defined(NO_GD) && !defined(AUTO_DECL)
39 # include "tbci/cplx_gd.h"
48 template <
typename T>
class cplx;
58 #ifdef CPLX_NEED_PUBLIC
75 #ifndef HAVE_PROMOTION_BUG
77 # ifndef HAVE_GCC295_TMPLFRNDCLS_BUG
78 template <
typename U>
friend class cplx;
91 { re = c.re;
im = c.
im;
return *
this; }
140 return cplx<T> ( (a * re) * den, (- a * im) * den );
165 double fabs ()
const;
194 bool operator < (const cplx<T>&
c)
const {
return fabssqr() <
c.fabssqr(); }
195 bool operator <= (const cplx<T>&
c)
const {
return fabssqr() <=
c.fabssqr(); }
201 friend STD__ ostream& operator << FGD (STD__ ostream&, const cplx< T >&);
211 template <
typename T>
217 template <
typename T>
220 re +=
a;
return *
this;
224 template <
typename T>
227 re += a.re;
im += a.
im;
return *
this;
230 template <
typename T>
233 re -=
a;
return *
this;
237 template <
typename T>
240 re -= a.re;
im -= a.
im;
return *
this;
244 template <
typename T>
247 re *=
a;
im *=
a;
return *
this;
251 template <
typename T>
255 re = tmp*a.re -
im*a.
im;
261 template <
typename T>
264 re /=
a;
im /=
a;
return *
this;
267 template <
typename T>
273 re = (tmp*a.re +
im*a.
im) / den;
274 im = (
im*a.re - tmp*a.
im) / den;
279 template <
typename T>
286 template <
typename T>
293 template <
typename T>
299 template <
typename T>
306 template <
typename T>
311 return cplx<T>( ( re*a.re +
im*a.
im ) * den, (
im*a.re - re*a.
im ) * den );
316 template <typename T>
318 {
return b.
plus (a); }
322 template <typename T>
324 {
return b.
minus (a); }
328 template <
typename T,
typename U>
335 template <typename T>
337 {
return b.
mult (a); }
341 template <typename T>
343 {
return b.
div (a); }
346 template <
typename T>
353 template <
typename T>
360 template <
typename T>
367 template <
typename T>
374 template <
typename T>
381 template <
typename T>
389 template <typename T>
394 template <
typename T>
410 template <
typename T>
426 template <
typename T>
442 return atan2 (0.0, re);
448 template <typename T>
459 template <typename T>
466 template <
typename T>
472 template <
typename T>
478 template <
typename T>
484 template <
typename T>
492 template <
typename T>
498 template <
typename T>
505 template <
typename T>
509 return 0.5 * (zi.
exp() + (-zi).
exp());
512 template <
typename T>
515 return 0.5 * (
exp() - (-(*this)).
exp());
518 template <
typename T>
521 return 0.5 * (
exp() + (-(*this)).
exp());
524 template <
typename T>
531 template <
typename T>
538 template <
typename T>
545 template <
typename T>
552 template <
typename T>
559 template <
typename T>
562 const cplx<T> arg = (1.0 + *
this) / (1.0 - *
this);
563 return 0.5 * arg.
ln();
567 #ifdef TBCI_CPLX_OLD_IOFMT
568 template <
typename T>
STD__ ostream& operator << (STD__ ostream& os, const cplx<T>&
c)
572 os <<
" - i " << -c.
im;
574 os <<
" + i " << c.
im;
590 template <
typename T>
594 char s =
'+', b =
'i', bra =
'(';
598 if (bra !=
'(') in.putback(bra);
602 if ((s !=
'+') && (s !=
'-')) in.putback(s);
604 if ((b !=
'i')) in.putback(b);
608 if (s ==
'-') c.
im =-
i;
614 if (bra !=
')') in.putback(bra);
621 template <
typename T>
STD__ ostream& operator << (STD__ ostream& os, const cplx<T>&
c)
623 return os <<
"(" << c.re <<
"," << c.
im <<
")";
626 template <
typename T>
637 c.re = r; c.
im = (
T)0;
644 c.re = r; c.
im = (
T)0;
662 template <typename T>
670 template <typename T>
673 template <
typename T>
680 template <typename T>
683 template <
typename T>
689 template <typename T>
691 {
return c.theta(); }
694 template <typename T>
705 template <typename T>
710 template <typename T>
711 inline TBCI__ cplx<T> _polar (
const T& r,
const T& p)
715 #if defined(__i386__) && defined(__GNUC__) && defined(USE_ASM) && defined(CPLX_ASM) && !defined(NO_DOUBLE_SPEC)
720 asm (
" fldl %3; fmull %5; fldl %2; fmull %4; fsubp %%st,%%st(1); \n\
721 fldl %2; fmull %5; fldl %3; fmull %4; faddp %%st,%%st(1); \n"
723 :
"g" (re),
"g" (
im),
"m" (a.re),
"m" (a.
im)
724 :
"st(6)",
"st(7)" );
729 #ifdef NEED_IMAG_UNIT
740 template <typename T>
745 template <typename T>
750 template <typename T>
755 template <typename T>
760 template <typename T>
762 {
return z.power (n); }
765 template <typename T>
767 {
return z.power (x); }
770 template <typename T>
775 template <typename T>
780 template <typename T>
785 template <typename T>
790 template <typename T>
795 template <typename T>
797 {
return z.sin()/z.cos(); }
800 template <typename T>
802 {
return z.sinh()/z.cosh(); }
805 template <typename T>
810 template <typename T>
812 {
return z.asinh(); }
815 template <typename T>
820 template <typename T>
822 {
return z.acosh(); }
825 template <typename T>
830 template <typename T>
832 {
return z.atanh(); }
835 template <typename T>
837 {
const static double InvLn10 = (1.0 /
log(10.0));
838 return z.ln()*InvLn10;
cplx< T > div(const T a) const
TBCI__ cplx< T > asin(const TBCI__ cplx< T > &z)
const Vector< T > const Vector< T > & x
const Vector< T > const Vector< T > const Vector< T > & p
TBCI__ cplx< T > tan(const TBCI__ cplx< T > &z)
bool operator>=(const cplx< T > &c) const
STD__ istream & operator>>(STD__ istream &istr, BdMatrix< T > &mat)
TBCI__ cplx< T > log(const TBCI__ cplx< T > &z)
TBCI__ cplx< T > cos(const TBCI__ cplx< T > &z)
double atan2(const double, const double)
#define SPEC_TBCI_TRAITS_ALWAYS_COPY(TYPE)
cplx< T > plus(const T v) const
cplx< T > operator*(const cplx< T > &) const
cplx< T > operator-() const
cplx< T > & operator-=(const T)
cplx< T > operator/(const cplx< T > &) const
TBCI__ cplx< T > atan(const TBCI__ cplx< T > &z)
#define NAMESPACE_CSTD_END
#define SPEC_TBCI_TRAITS_LOOP_COPY(TYPE)
TBCI__ cplx< T > atanh(const TBCI__ cplx< T > &z)
cplx(const T r, const T i=(T) 0)
cplx< T > expi(const T phi)
const Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > & z
TBCI__ cplx< T > log10(const TBCI__ cplx< T > &z)
T arg(const TBCI__ cplx< T > &c)
TBCI__ cplx< T > tanh(const TBCI__ cplx< T > &z)
TBCI__ cplx< T > acosh(const TBCI__ cplx< T > &z)
bool operator!=(const cplx< T > &c) const
cplx< T > operator+(const cplx< T > &) const
cplx< T > sqr(const cplx< T > &c)
cplx< T > & operator/=(const T)
TBCI__ cplx< T > sin(const TBCI__ cplx< T > &z)
cplx< T > & operator=(const T r)
cplx< T > operator~() const
TBCI__ cplx< T > exp(const TBCI__ cplx< T > &z)
BdMatrix< T > operator*(const T &v, const BdMatrix< T > &m)
bool operator>(const cplx< T > &c) const
int conj(const int arg)
conj for elementary types
cplx< T > & operator*=(const T)
T dot(const T &a1, const T &a2)
#define NAMESPACE_CPLX_END
cplx< T > & operator+=(const T)
TBCI__ cplx< T > asinh(const TBCI__ cplx< T > &z)
cplx< T > minus(const T v) const
cplx< T > & set(const T r, const T i)
T aligned_value_type TALIGN(MIN_ALIGN)
double fabssqr(const double a)
double norm(const TBCI__ cplx< T > &c)
TBCI__ cplx< T > sinh(const TBCI__ cplx< T > &z)
const unsigned TMatrix< T > const Matrix< T > * a
cplx< T > mult(const T v) const
const Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > long int int char v
< find minimun of func on grid with resolution res
TBCI__ cplx< T > pow(const TBCI__ cplx< T > &z, const double n)
TBCI__ cplx< T > cosh(const TBCI__ cplx< T > &z)
TBCI__ cplx< T > acos(const TBCI__ cplx< T > &z)
bool operator==(const cplx< T > &c) const
#define LIKELY(expr)
branch prediction note that we sometimes on purpose mark the unlikely possibility likely and vice ver...
friend cplx< T > dot FGD(const cplx< T > &, const cplx< T > &)
cplx< T > power(const double) const
NAMESPACE_CPLX_END NAMESPACE_TBCI TBCI__ cplx< T > polar(const T &r, const T &p)