00001
00007
00008
00009
00010
00011 #ifndef TBCI_STD_CPLX_H
00012 #define TBCI_STD_CPLX_H
00013
00014 #include "basics.h"
00015 #ifndef HAVE_NO_NEW_HEADERS_BUG
00016 # include <complex>
00017 #else
00018 # include <complex.h>
00019 #endif
00020
00021
00022 #ifndef CPLX
00023 # define CPLX(t) CPLX__ complex<t>
00024 # define CPLXR(t,a,r) CPLX__ complex<t> a (r)
00025 # define CPLXRI(t,a,r,i) CPLX__ complex<t> a (r,i)
00026 # define CPLXC(t,a,c) CPLX__ complex<t> a (c)
00027 # define CPLXVRI(t,r,i) (CPLX__ complex<t>(r,i))
00028 #endif
00029
00030
00031
00032
00033 NAMESPACE_TBCI
00034
00035 #ifndef TEMPLATED_FABSSQR // We do need it as the fabssqr() in basics.h is templated!
00036 INST(template <typename T> class CPLX__ complex friend double fabssqr (const CPLX__ complex<T>&);)
00037 template <typename T>
00038 inline double fabssqr (const CPLX__ complex<T>& a)
00039 { return (a.real()*a.real() + a.imag()*a.imag()); }
00040 #endif
00041 NAMESPACE_END
00042
00043 NAMESPACE_CSTD
00044 INST(template <typename T> class CPLX__ complex friend double fabs (const CPLX__ complex<T>&);)
00045 template <typename T>
00046 inline double fabs (const CPLX__ complex<T>& a)
00047
00048 { return GLBL__ MATH__ sqrt (TBCI__ fabssqr (a)); }
00049 NAMESPACE_CSTD_END
00050
00051 #if 0
00052 template <typename T>
00053 inline bool operator == (const CPLX__ complex<T>&a, const T d)
00054 { return (a.imag() == 0 && a.real() == d); }
00055 #endif
00056
00057 #if 0
00058 NAMESPACE_CPLX
00059
00060 INST(template <typename T> class CPLX__ complex friend T real (const CPLX__ complex<T>&);)
00061 template <typename T>
00062 inline T real (const CPLX__ complex<T>& z)
00063 { return CPLX__ real(z); }
00064
00065 INST(template <typename T> class CPLX__ complex friend T imag (const CPLX__ complex<T>&);)
00066 template <typename T>
00067 inline T imag (const CPLX__ complex<T>& z)
00068 { return CPLX__ imag(z); }
00069
00070 INST(template <typename T> class CPLX__ complex friend CPLX__ complex<T> conj (const CPLX__ complex<T>&);)
00071 template <typename T>
00072 inline CPLX__ complex<T> conj (const CPLX__ complex<T>& z)
00073 { return CPLX__ complex<T> (z.real(), -z.imag()); }
00074
00075 NAMESPACE_CPLX_END
00076 #endif
00077
00078 #if !defined(NO_NS) && !defined(HAVE_IGNORE_STD_NS_BUG) && defined(HAVE_LIBC_GLOBAL_NS_BUG) && (!defined(HAVE_CPP_GLOBAL_NS_BUG) || !defined(HAVE_CPLX_GLOBAL_NS_BUG))
00079 # define NEED_CPLX_TO_CSTD 1
00080 #endif
00081
00082 #ifdef NEED_CPLX_TO_CSTD
00083
00084 NAMESPACE_CSTD
00085 template <typename T>
00086 inline CPLX__ complex<T> sqrt (const CPLX__ complex<T>& z)
00087 { return CPLX__ sqrt (z); }
00088
00089
00090 #ifndef _MSC_VER
00091 template <typename T>
00092 inline CPLX__ complex<T> exp (const CPLX__ complex<T>& z)
00093 { return CPLX__ exp (z); }
00094 #endif
00095 NAMESPACE_CSTD_END
00096
00097 #endif
00098
00099 NAMESPACE_CPLX
00100
00101 INST(template <typename T> class CPLX__ complex friend bool operator > (const CPLX__ complex<T>&, const CPLX__ complex<T>&);)
00105 template <typename T>
00106 inline bool operator > (const CPLX__ complex<T>& a, const CPLX__ complex<T>& b)
00107 { return (MATH__ fabs(a) > MATH__ fabs(b)); }
00108
00109 INST(template <typename T> class CPLX__ complex friend bool operator >= (const CPLX__ complex<T>&, const CPLX__ complex<T>&);)
00110 template <typename T>
00111 inline bool operator >= (const CPLX__ complex<T>& a, const CPLX__ complex<T>& b)
00112 { return (MATH__ fabs(a) >= MATH__ fabs(b)); }
00113
00114 INST(template <typename T> class CPLX__ complex friend bool operator < (const CPLX__ complex<T>&, const CPLX__ complex<T>&);)
00115 template <typename T>
00116 inline bool operator < (const CPLX__ complex<T>& a, const CPLX__ complex<T>& b)
00117 { return (MATH__ fabs(a) < MATH__ fabs(b)); }
00118
00119 INST(template <typename T> class CPLX__ complex friend bool operator <= (const CPLX__ complex<T>&, const CPLX__ complex<T>&);)
00120 template <typename T>
00121 inline bool operator <= (const CPLX__ complex<T>& a, const CPLX__ complex<T>& b)
00122 { return (MATH__ fabs(a) <= MATH__ fabs(b)); }
00123
00124
00125
00126
00127
00128 #ifdef HAVE_MISS_STDCPLX_FANCY_FN_BUG
00129 INST(template <typename T> class CPLX__ complex friend CPLX__ complex<T> acos (const CPLX__ complex<T>&);)
00130 template <typename T>
00131 inline CPLX__ complex<T> acos (const CPLX__ complex<T> &x)
00132 {
00133 return CPLX__ complex<T>(0,-1)*log(x+sqrt(x*x-CPLX__ complex<T>(1,0)));
00134 }
00135
00136 INST(template <typename T> class CPLX__ complex friend CPLX__ complex<T> asin (const CPLX__ complex<T> &);)
00137 template <typename T>
00138 inline CPLX__ complex<T> asin (const CPLX__ complex<T> &x)
00139 {
00140 return CPLX__ complex<T>(0,-1)*log(CPLX__ complex<T>(0,1)*x+sqrt(CPLX__ complex<T>(1,0)-x*x));
00141 }
00142
00143 INST(template <typename T> class CPLX__ complex friend CPLX__ complex<T> atan (const CPLX__ complex<T> &);)
00144 template <typename T>
00145 inline CPLX__ complex<T> atan (const CPLX__ complex<T> &x)
00146 {
00147 return acos( 1.0/sqrt(x*x+CPLX__ complex<T>(1,0)) );
00148 }
00149
00150 INST(template <typename T> class CPLX__ complex friend CPLX__ complex<T> atanh (const CPLX__ complex<T> &);)
00151 template <typename T>
00152 inline CPLX__ complex<T> atanh (const CPLX__ complex<T> &x)
00153 {
00154 CPLX__ complex<T> arg = (1.0 + x) / (1.0 - x);
00155 return 0.5 * MATH__ log(arg);
00156 }
00157
00158 #endif
00159 #ifdef MISS_STDCPLX_TAN_BUG
00160 INST(template <typename T> class CPLX__ complex friend CPLX__ complex<T> tan(const CPLX__ complex<T> &);)
00161 template <typename T>
00162 inline CPLX__ complex<T> tan(const CPLX__ complex<T> &x)
00163 {
00164 return sin(x)/cos(x);
00165 }
00166
00167 INST(template <typename T> class CPLX__ complex friend CPLX__ complex<T> tanh(const CPLX__ complex<T> &);)
00168 template <typename T>
00169 inline CPLX__ complex<T> tanh(const CPLX__ complex<T> &x)
00170 {
00171 return sinh(x)/cosh(x);
00172 }
00173 #endif
00174 #ifdef HAVE_MISS_STDCPLX_LOG10_BUG
00175 INST(template <typename T> class CPLX__ complex friend CPLX__ complex<T> log10(const CPLX__ complex<T> &);)
00176 template <typename T>
00177 inline CPLX__ complex<T> log10(const CPLX__ complex<T> &x)
00178 {
00179 const static double InvLn10(1.0/GLBL__ MATH__ log(10));
00180 return log(x)*InvLn10;
00181 }
00182 #endif
00183
00184 NAMESPACE_CPLX_END
00185
00186 NAMESPACE_TBCI
00187 #ifdef NEED_IMAG_UNIT
00188 const CPLXRI(double,Imag_unit,0.0,1.0);
00189 #endif
00190 NAMESPACE_END
00191
00192 #ifdef HAVE_MISS_CPLX_IO_BUG
00193
00194 template <typename T>
00195 STD__ ostream& operator << (STD__ ostream& os, const CPLX__ complex<T>& v)
00196 {
00197 return os << "(" << v.real() << "," << v.imag() << ")";
00198 }
00199
00200
00201 template <typename T>
00202 STD__ istream& operator >> (STD__ istream& is, CPLX__ complex<T>& v)
00203 {
00204 char bra; T re, im = 0;
00205 is >> bra;
00206 is >> re;
00207 if (bra != '(') {
00208 v = CPLX__ complex<T> (re, im);
00209 return is;
00210 }
00211 is >> bra;
00212 if (bra != ',') {
00213 if (bra != ')')
00214 STD__ cerr << "Error parsing complex!" << STD__ endl;
00215 v = CPLX__ complex<T> (re, im);
00216 return is;
00217 }
00218 is >> im;
00219 is >> bra;
00220 if (bra != ')')
00221 STD__ cerr << "Error parsing complex!" << STD__ endl;
00222 v = CPLX__ complex<T> (re, im);
00223 return is;
00224 }
00225 #endif
00226
00227 NAMESPACE_TBCI
00228 #ifdef MALLOC_CACHE
00229 SPECIALIZE_MEMALLOC2(CPLX__ complex<double>,stdcomplex_double)
00230 typedef CPLX__ complex<double>* stdcomplexdoubleptr;
00231 SPECIALIZE_MEMALLOC(stdcomplexdoubleptr)
00232 SPECIALIZE_MEMALLOC2(CPLX__ complex<float>,stdcomplex_float)
00233 typedef CPLX__ complex<float>* stdcomplexfloatptr;
00234 SPECIALIZE_MEMALLOC(stdcomplexfloatptr)
00235 #endif
00236
00237
00238
00239 SPEC_TBCI_TRAITS_LOOP_COPY(CPLX__ complex<float>);
00240 SPEC_TBCI_TRAITS_LOOP_COPY(CPLX__ complex<double>);
00241 SPEC_TBCI_TRAITS_ALWAYS_COPY(CPLX__ complex<float>*);
00242 SPEC_TBCI_TRAITS_ALWAYS_COPY(CPLX__ complex<double>*);
00243
00244 NAMESPACE_END
00245
00246 #endif