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"
48template <
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;
220 re +=
a;
return *
this;
227 re +=
a.re;
im +=
a.im;
return *
this;
233 re -=
a;
return *
this;
240 re -=
a.re;
im -=
a.im;
return *
this;
247 re *=
a;
im *=
a;
return *
this;
255 re = tmp*
a.re -
im*
a.im;
264 re /=
a;
im /=
a;
return *
this;
273 re = (tmp*
a.re +
im*
a.im) / den;
274 im = (
im*
a.re - tmp*
a.im) / den;
311 return cplx<T>( ( re*
a.re +
im*
a.im ) * den, (
im*
a.re - re*
a.im ) * den );
318{
return b.plus (
a); }
324{
return b.minus (
a); }
328template <
typename T,
typename U>
330{
return cplx<T> (f*
c.real(), f*
c.imag()); }
337{
return b.mult (
a); }
391{
return c.fabssqr(); }
442 return atan2 (0.0, re);
509 return 0.5 * (zi.
exp() + (-zi).
exp());
515 return 0.5 * (
exp() - (-(*this)).
exp());
521 return 0.5 * (
exp() + (-(*this)).
exp());
562 const cplx<T> arg = (1.0 + *
this) / (1.0 - *
this);
563 return 0.5 *
arg.ln();
567#ifdef TBCI_CPLX_OLD_IOFMT
572 os <<
" - i " << -
c.im;
574 os <<
" + i " <<
c.im;
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);
623 return os <<
"(" <<
c.re <<
"," <<
c.im <<
")";
637 c.re = r;
c.im = (
T)0;
644 c.re = r;
c.im = (
T)0;
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)" );
762{
return z.power (n); }
767{
return z.power (
x); }
797{
return z.sin()/z.cos(); }
802{
return z.sinh()/z.cosh(); }
837{
const static double InvLn10 = (1.0 /
log(10.0));
838 return z.ln()*InvLn10;
const Vector< T > const Vector< T > const Vector< T > & p
const Vector< T > const Vector< T > & x
#define LIKELY(expr)
branch prediction note that we sometimes on purpose mark the unlikely possibility likely and vice ver...
#define NAMESPACE_CPLX_END
#define NAMESPACE_CSTD_END
cplx< T > & set(const T r, const T i)
cplx< T > & operator-=(const T)
cplx< T > & operator/=(const T)
cplx< T > & operator+=(const T)
cplx< T > & operator*=(const T)
bool operator!=(const cplx< T > &c) const
bool operator<=(const cplx< T > &c) const
friend cplx< T > dot FGD(const cplx< T > &, const cplx< T > &)
cplx< T > operator/(const cplx< T > &) const
cplx< T > power(const double) const
cplx< T > plus(const T v) const
bool operator==(const cplx< T > &c) const
cplx< T > operator-() const
bool operator>(const cplx< T > &c) const
cplx< T > operator+(const cplx< T > &) const
cplx< T > div(const T a) const
T aligned_value_type TALIGN(MIN_ALIGN)
bool operator<(const cplx< T > &c) const
cplx< T > & operator=(const T r)
cplx(const T r, const T i=(T) 0)
cplx< T > minus(const T v) const
cplx< T > operator~() const
cplx< T > mult(const T v) const
bool operator>=(const cplx< T > &c) const
cplx< T > operator*(const cplx< T > &) const
T imag(const TBCI__ cplx< T > &z)
double fabs(const TBCI__ cplx< T > &c)
TBCI__ cplx< T > sinh(const TBCI__ cplx< T > &z)
cplx< T > expi(const T phi)
TBCI__ cplx< T > asinh(const TBCI__ cplx< T > &z)
T arg(const TBCI__ cplx< T > &c)
TBCI__ cplx< T > acosh(const TBCI__ cplx< T > &z)
cplx< T > dot(const cplx< T > &a, const cplx< T > &b)
TBCI__ cplx< T > pow(const TBCI__ cplx< T > &z, const double n)
TBCI__ cplx< T > atan(const TBCI__ cplx< T > &z)
TBCI__ cplx< T > tan(const TBCI__ cplx< T > &z)
TBCI__ cplx< T > exp(const TBCI__ cplx< T > &z)
TBCI__ cplx< T > asin(const TBCI__ cplx< T > &z)
double fabssqr(const cplx< T > &c)
cplx< T > sqr(const cplx< T > &c)
cplx< T > operator*(const T a, const cplx< T > &b)
NAMESPACE_END NAMESPACE_CPLX TBCI__ cplx< T > conj(const TBCI__ cplx< T > &c)
double norm(const TBCI__ cplx< T > &c)
TBCI__ cplx< T > log(const TBCI__ cplx< T > &z)
STD__ istream & operator>>(STD__ istream &in, cplx< T > &c)
TBCI__ cplx< T > sin(const TBCI__ cplx< T > &z)
TBCI__ cplx< T > acos(const TBCI__ cplx< T > &z)
TBCI__ cplx< T > cosh(const TBCI__ cplx< T > &z)
NAMESPACE_END NAMESPACE_CSTD TBCI__ cplx< T > sqrt(const TBCI__ cplx< T > &z)
TBCI__ cplx< T > atanh(const TBCI__ cplx< T > &z)
TBCI__ cplx< T > tanh(const TBCI__ cplx< T > &z)
STD__ ostream & operator<<(STD__ ostream &os, const cplx< T > &c)
TBCI__ cplx< T > cos(const TBCI__ cplx< T > &z)
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)
#define SPEC_TBCI_TRAITS_ALWAYS_COPY(TYPE)
#define SPEC_TBCI_TRAITS_LOOP_COPY(TYPE)