TBCI Numerical high perf. C++ Library 2.8.0
std_cplx.h
Go to the documentation of this file.
1
6
7// Written: KG 97/11/30
8// Changed: KG 97/11/30
9// $Id: std_cplx.h,v 1.5.2.29 2019/05/28 11:13:02 garloff Exp $
10
11#ifndef TBCI_STD_CPLX_H
12#define TBCI_STD_CPLX_H
13
14#include "tbci/basics.h"
15#ifndef HAVE_NO_NEW_HEADERS_BUG
16# include <complex>
17#else
18# include <complex.h>
19#endif
20
21//#define cplx complex
22#ifndef CPLX
23# define CPLX(t) CPLX__ complex<t>
24# define CPLXR(t,a,r) CPLX__ complex<t> a (r)
25# define CPLXRI(t,a,r,i) CPLX__ complex<t> a (r,i)
26# define CPLXC(t,a,c) CPLX__ complex<t> a (c)
27# define CPLXVRI(t,r,i) (CPLX__ complex<t>(r,i))
28#endif
29
30//typedef typename T complex<T>::cplx_base;
31//typedef complex<T> complex<T>::cplx_t;
32
34// compat
35#ifndef TEMPLATED_FABSSQR // We do need it as the fabssqr() in basics.h is templated!
36INST(template <typename T> class CPLX__ complex friend double fabssqr (const CPLX__ complex<T>&);)
37template <typename T>
38inline double fabssqr (const CPLX__ complex<T>& a)
39{ return (a.real()*a.real() + a.imag()*a.imag()); }
40#endif
42
43#ifndef HAVE_STDCPLX_FABS
45INST(template <typename T> class CPLX__ complex friend double fabs (const CPLX__ complex<T>&);)
46template <typename T>
47inline double fabs (const CPLX__ complex<T>& a)
48//{ return abs(a); }
49{ return GLBL__ MATH__ sqrt (TBCI__ fabssqr (a)); }
51#endif
52
53#if 0
54template <typename T>
55inline bool operator == (const CPLX__ complex<T>&a, const T d)
56{ return (a.imag() == 0 && a.real() == d); }
57#endif
58
59#if 0
61
62INST(template <typename T> class CPLX__ complex friend T real (const CPLX__ complex<T>&);)
63template <typename T>
64inline T real (const CPLX__ complex<T>& z)
65{ return CPLX__ real(z); }
66
67INST(template <typename T> class CPLX__ complex friend T imag (const CPLX__ complex<T>&);)
68template <typename T>
69inline T imag (const CPLX__ complex<T>& z)
70{ return CPLX__ imag(z); }
71
72INST(template <typename T> class CPLX__ complex friend CPLX__ complex<T> conj (const CPLX__ complex<T>&);)
73template <typename T>
74inline CPLX__ complex<T> conj (const CPLX__ complex<T>& z)
75{ return CPLX__ complex<T> (z.real(), -z.imag()); }
76
78#endif
79
80#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))
81# define NEED_CPLX_TO_CSTD 1
82#endif
83
84#ifdef NEED_CPLX_TO_CSTD
85//#if !defined(NO_NS) && defined(HAVE_LIBC_GLOBAL_NS_BUG) && (!defined(HAVE_CPP_GLOBAL_NS_BUG) || !defined(HAVE_CPLX_GLOBAL_NS_BUG))
87template <typename T>
88inline CPLX__ complex<T> sqrt (const CPLX__ complex<T>& z)
89{ return CPLX__ sqrt (z); }
90// exp seems to be needed in :: by DEC CXX. Does it break on MSVC?
91//#if defined(HAVE_CPP_GLOBAL_NS_BUG)
92#ifndef _MSC_VER
93template <typename T>
94inline CPLX__ complex<T> exp (const CPLX__ complex<T>& z)
95{ return CPLX__ exp (z); }
96#endif
98//#endif
99#endif
100
102// Mathematically thought, the following is nonsense ...
103INST(template <typename T> class CPLX__ complex friend bool operator > (const CPLX__ complex<T>&, const CPLX__ complex<T>&);)
107template <typename T>
108inline bool operator > (const CPLX__ complex<T>& a, const CPLX__ complex<T>& b)
109{ return (MATH__ fabs(a) > MATH__ fabs(b)); }
110
111INST(template <typename T> class CPLX__ complex friend bool operator >= (const CPLX__ complex<T>&, const CPLX__ complex<T>&);)
112template <typename T>
113inline bool operator >= (const CPLX__ complex<T>& a, const CPLX__ complex<T>& b)
114{ return (MATH__ fabs(a) >= MATH__ fabs(b)); }
115
116INST(template <typename T> class CPLX__ complex friend bool operator < (const CPLX__ complex<T>&, const CPLX__ complex<T>&);)
117template <typename T>
118inline bool operator < (const CPLX__ complex<T>& a, const CPLX__ complex<T>& b)
119{ return (MATH__ fabs(a) < MATH__ fabs(b)); }
120
121INST(template <typename T> class CPLX__ complex friend bool operator <= (const CPLX__ complex<T>&, const CPLX__ complex<T>&);)
122template <typename T>
123inline bool operator <= (const CPLX__ complex<T>& a, const CPLX__ complex<T>& b)
124{ return (MATH__ fabs(a) <= MATH__ fabs(b)); }
125
126
127/* From and for PLASIMO ... */
128/* We dont't need all those CPLX__ namespace specifications, as we are
129 * inside NAMESPACE_STD */
130#ifdef HAVE_MISS_STDCPLX_FANCY_FN_BUG
131INST(template <typename T> class CPLX__ complex friend CPLX__ complex<T> acos (const CPLX__ complex<T>&);)
132template <typename T>
133inline CPLX__ complex<T> acos (const CPLX__ complex<T> &x)
134{
135 return CPLX__ complex<T>(0,-1)*log(x+sqrt(x*x-CPLX__ complex<T>(1,0)));
136}
137
138INST(template <typename T> class CPLX__ complex friend CPLX__ complex<T> asin (const CPLX__ complex<T> &);)
139template <typename T>
140inline CPLX__ complex<T> asin (const CPLX__ complex<T> &x)
141{
142 return CPLX__ complex<T>(0,-1)*log(CPLX__ complex<T>(0,1)*x+sqrt(CPLX__ complex<T>(1,0)-x*x));
143}
144
145INST(template <typename T> class CPLX__ complex friend CPLX__ complex<T> atan (const CPLX__ complex<T> &);)
146template <typename T>
147inline CPLX__ complex<T> atan (const CPLX__ complex<T> &x)
148{
149 return acos( 1.0/sqrt(x*x+CPLX__ complex<T>(1,0)) );
150}
151
152INST(template <typename T> class CPLX__ complex friend CPLX__ complex<T> atanh (const CPLX__ complex<T> &);)
153template <typename T>
155{
156 CPLX__ complex<T> arg = (1.0 + x) / (1.0 - x);
157 return 0.5 * MATH__ log(arg);
158}
159
160#endif /* MISS_STDCPLX_FANCY_FN */
161#ifdef MISS_STDCPLX_TAN_BUG
162INST(template <typename T> class CPLX__ complex friend CPLX__ complex<T> tan(const CPLX__ complex<T> &);)
163template <typename T>
164inline CPLX__ complex<T> tan(const CPLX__ complex<T> &x)
165{
166 return sin(x)/cos(x);
167}
168
169INST(template <typename T> class CPLX__ complex friend CPLX__ complex<T> tanh(const CPLX__ complex<T> &);)
170template <typename T>
172{
173 return sinh(x)/cosh(x);
174}
175#endif
176#ifdef HAVE_MISS_STDCPLX_LOG10_BUG
177INST(template <typename T> class CPLX__ complex friend CPLX__ complex<T> log10(const CPLX__ complex<T> &);)
178template <typename T>
180{
181 const static double InvLn10(1.0/GLBL__ MATH__ log(10));
182 return log(x)*InvLn10;
183}
184#endif /* MISS_STDCPLX_LOG10 */
185
187
189#ifdef NEED_IMAG_UNIT
190const CPLXRI(double,Imag_unit,0.0,1.0);
191#endif
193
194#ifdef HAVE_MISS_CPLX_IO_BUG
195//INST(template <typename T> class CPLX__ complex friend STD__ ostream operator << (STD__ ostream&, const CPLX__ complex<T>&);)
196template <typename T>
197STD__ ostream& operator << (STD__ ostream& os, const CPLX__ complex<T>& v)
198{
199 return os << "(" << v.real() << "," << v.imag() << ")";
200}
201
202//INST(template <typename T> class CPLX__ complex friend STD__ istream operator >> (STD__ istream&, CPLX__ complex<T>&);)
203template <typename T>
204STD__ istream& operator >> (STD__ istream& is, CPLX__ complex<T>& v)
205{
206 char bra; T re, im = 0;
207 is >> bra;
208 is >> re;
209 if (bra != '(') {
210 v = CPLX__ complex<T> (re, im);
211 return is;
212 }
213 is >> bra;
214 if (bra != ',') {
215 if (bra != ')')
216 STD__ cerr << "Error parsing complex!" << STD__ endl;
217 v = CPLX__ complex<T> (re, im);
218 return is;
219 }
220 is >> im;
221 is >> bra;
222 if (bra != ')')
223 STD__ cerr << "Error parsing complex!" << STD__ endl;
224 v = CPLX__ complex<T> (re, im);
225 return is;
226}
227#endif
228
230#ifdef MALLOC_CACHE
232typedef CPLX__ complex<double>* stdcomplexdoubleptr;
233SPECIALIZE_MEMALLOC(stdcomplexdoubleptr)
235typedef CPLX__ complex<float>* stdcomplexfloatptr;
236SPECIALIZE_MEMALLOC(stdcomplexfloatptr)
237#endif
238
239/* If used in loops, a single copy is still cheaper than pointer
240 * indirection */
245
247
248#endif /* TBCI_STD_CPLX_H */
const Vector< T > const Vector< T > & x
Definition LM_fit.h:97
STD__ istream & operator>>(STD__ istream &istr, BdMatrix< T > &mat)
STD__ ostream & operator<<(STD__ ostream &ostr, const BdMatrix< T > &mat)
#define STD__
Definition basics.h:338
#define NAMESPACE_CSTD
Definition basics.h:319
#define NAMESPACE_CPLX_END
Definition basics.h:326
#define NAMESPACE_END
Definition basics.h:323
#define INST(x)
Definition basics.h:238
#define NAMESPACE_CSTD_END
Definition basics.h:325
#define NAMESPACE_TBCI
Definition basics.h:317
#define TBCI__
Definition basics.h:332
#define MATH__
Definition basics.h:339
#define GLBL__
Definition basics.h:342
#define NAMESPACE_CPLX
Definition basics.h:322
#define T
Definition bdmatlib.cc:20
T imag(const TBCI__ cplx< T > &z)
Definition cplx.h:674
double fabs(const TBCI__ cplx< T > &c)
Definition cplx.h:746
TBCI__ cplx< T > sinh(const TBCI__ cplx< T > &z)
Definition cplx.h:781
T arg(const TBCI__ cplx< T > &c)
Definition cplx.h:690
TBCI__ cplx< T > atan(const TBCI__ cplx< T > &z)
Definition cplx.h:826
TBCI__ cplx< T > tan(const TBCI__ cplx< T > &z)
Definition cplx.h:796
TBCI__ cplx< T > exp(const TBCI__ cplx< T > &z)
Definition cplx.h:756
TBCI__ cplx< T > asin(const TBCI__ cplx< T > &z)
Definition cplx.h:806
double fabssqr(const cplx< T > &c)
Definition cplx.h:390
NAMESPACE_END NAMESPACE_CPLX TBCI__ cplx< T > conj(const TBCI__ cplx< T > &c)
Definition cplx.h:663
TBCI__ cplx< T > log(const TBCI__ cplx< T > &z)
Definition cplx.h:771
TBCI__ cplx< T > sin(const TBCI__ cplx< T > &z)
Definition cplx.h:776
TBCI__ cplx< T > acos(const TBCI__ cplx< T > &z)
Definition cplx.h:816
TBCI__ cplx< T > cosh(const TBCI__ cplx< T > &z)
Definition cplx.h:791
NAMESPACE_END NAMESPACE_CSTD TBCI__ cplx< T > sqrt(const TBCI__ cplx< T > &z)
Definition cplx.h:751
TBCI__ cplx< T > atanh(const TBCI__ cplx< T > &z)
Definition cplx.h:831
TBCI__ cplx< T > tanh(const TBCI__ cplx< T > &z)
Definition cplx.h:801
TBCI__ cplx< T > cos(const TBCI__ cplx< T > &z)
Definition cplx.h:786
bool operator==(const F_BandMatrix< T > &m1, const F_BandMatrix< T > &m2)
F_TMatrix< T > b
Definition f_matrix.h:736
#define SPECIALIZE_MEMALLOC2(TYPE, SHTP)
#define SPECIALIZE_MEMALLOC(TYPE)
const unsigned TMatrix< T > const Matrix< T > * a
#define complex
#define real
NAMESPACE_END NAMESPACE_CSTD double fabs(const CPLX__ complex< T > &a)
Definition std_cplx.h:47
#define CPLXRI(t, a, r, i)
Definition std_cplx.h:25
#define SPEC_TBCI_TRAITS_ALWAYS_COPY(TYPE)
Definition tbci_traits.h:56
#define SPEC_TBCI_TRAITS_LOOP_COPY(TYPE)
Definition tbci_traits.h:71
#define log10