TBCI Numerical high perf. C++ Library  2.8.0
cplx.h
Go to the documentation of this file.
1 
5 //-------------------------------------------------------------
6 // by amb 24/06/97
7 // last modification 1997-06-24 amb
8 // 1997-12-13 kg
9 // $Id: cplx.h,v 1.37.2.45 2022/11/03 17:28:10 garloff Exp $
10 //-------------------------------------------------------------
11 
12 
13 #ifndef TBCI_CPLX_H
14 #define TBCI_CPLX_H
15 
16 #include "tbci/basics.h"
17 #ifndef TBCI_CPLX_DONT_INCLUDE_CONSTANTS
18 # include "tbci/constants.h"
19 #endif
20 
21 #ifdef PRAGMA_I
22 # pragma interface "cplx.h"
23 #endif
24 
25 
26 #if defined(__GNUC__) && defined (USE_BUILTIN_CPLX)
27 # include "tbci/builtin_cplx.h"
28 #endif
29 
30 #ifndef CPLX
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))
36 #endif
37 
38 #if !defined(NO_GD) && !defined(AUTO_DECL)
39 # include "tbci/cplx_gd.h"
40 #endif
41 
42 //#include <cmath>
43 
45 
46 // These are necessary to avoid -fguiding-decls
47 
48 template <typename T> class cplx;
49 
54 template <typename T>
55 class cplx
56 {
57  protected:
58 #ifdef CPLX_NEED_PUBLIC
59  public:
60 #endif
62 
63  public:
64 
65  typedef T value_type;
66  typedef T aligned_value_type TALIGN(MIN_ALIGN);
67  typedef T cplx_base;
68  typedef cplx<T> cplx_t;
69  // constructors & destructors
70 
71  cplx () {}
72  cplx (const T r, const T i = (T)0) : re(r), im(i) {}
73  cplx (const cplx<T>& c) : re(c.re), im(c.im) {}
74 
75 #ifndef HAVE_PROMOTION_BUG
76  // Promotion (only explicit)
77 # ifndef HAVE_GCC295_TMPLFRNDCLS_BUG
78  template <typename U> friend class cplx;
79  template <typename U> explicit cplx (const cplx<U>& c) : re(c.re), im(c.im) {}
80 # else
81  template <typename U> explicit cplx (const cplx<U>& c) : re(c.real()), im(c.imag()) {}
82 # endif
83 #endif
84  //cplx (const cplx<double>& c) : re(c.re), im(c.im) {}
85  ~cplx () {}
86 
87  // assignment operators
88 
89  cplx<T>& operator = (const T r) { re = r; im = (T)0; return *this; }
91  { re = c.re; im = c.im; return *this; }
92  //{ CSTD__ memcpy &(this->re), &(c.re), 2 * sizeof (re)); return *this; }
93 
94  cplx<T>& operator += (const T);
95  cplx<T>& operator += (const cplx<T>&);
96  cplx<T>& operator -= (const T);
97  cplx<T>& operator -= (const cplx<T>&);
98  cplx<T>& operator *= (const T);
99  cplx<T>& operator *= (const cplx<T>&);
100  cplx<T>& operator /= (const T);
101  cplx<T>& operator /= (const cplx<T>&);
102 
103  // member access
104  cplx<T>& set (const T r, const T i) { re = r; im = i; return *this; }
105  // ro
106  T real () const { return re; }
107  T imag () const { return im; }
108  // rw
109  T& real () { return re; }
110  T& imag () { return im; }
111 
112  // cast a cplx to a double: Don't allow silent info loss
113  //operator double () const { return re; }
114 
115  // member access (read-only)
116 
117  // basic algebra & negation
118  cplx<T> operator + (const cplx<T>&) const;
119  cplx<T> operator - (const cplx<T>&) const;
120  //note: first argument does not become conjugated !
121  cplx<T> operator * (const cplx<T>&) const;
122  //note: first argument becomes conjugated !
123  friend cplx<T> /*FRIEND_TBCI2__*/ dot FGD (const cplx<T>&, const cplx<T>&);
124  cplx<T> operator / (const cplx<T>&) const;
125 
126  //for friend cplx<T> operator + FGD (const T, const cplx<T>&);
127  cplx<T> plus (const T v) const
128  { return cplx<T> (v+re, im); }
129  //for friend cplx<T> operator - FGD (const T, const cplx<T>&);
130  cplx<T> minus (const T v) const
131  { return cplx<T> (v-re, -im); }
132  //for friend cplx<T> operator * FGD (const T, const cplx<T>&);
133  cplx<T> mult (const T v) const
134  { return cplx<T> (v*re, v*im); }
135  //friend cplx<S> operator * (const T f, const cplx<S>& c);
136  //for friend cplx<T> operator / FGD (const T, const cplx<T>&);
137  cplx<T> div (const T a) const
138  {
139  REGISTER const T den ALIGN(MIN_ALIGN) = (T)1 / (re*re + im*im);
140  return cplx<T> ( (a * re) * den, (- a * im) * den );
141  }
142 
143  cplx<T> operator + (const T) const;
144  cplx<T> operator - (const T) const;
145  cplx<T> operator * (const T) const;
146  cplx<T> operator / (const T) const;
147  cplx<T> operator - () const;
148  cplx<T> operator ~ () const;
149 
150  // other functions
151 
152  T theta () const;
153  // alias
154  //friend T arg (const cplx<T>& c) { return c.theta(); }
155  //friend cplx<T> /*FRIEND_TBCI2__*/ expi FGD (const T);
156  //friend cplx<T> /*FRIEND_TBCI2__*/ sqr FGD (const cplx<T>&);
157 
158  cplx<T> conj () const { return cplx<T> (re, -im); }
159  //friend cplx<T> conj FGD (const cplx<T>&);
160 
161  //the variant that changes(!) the object
162  cplx<T>& do_conj () { im = -im; return *this; }
163 
164  double fabssqr () const { return (double)(re*re + im*im); }
165  double fabs () const; //{ return MATH__ sqrt (re*re + im*im); }
166  double norm () const { return fabssqr(); } // oops!
167  T abs () const; //{ return sqrt (re*re + im*im); }
168 
169  cplx<T> exp () const;
170  cplx<T> sqrt () const;
171 
172  cplx<T> power (const double) const;
173  cplx<T> power (const cplx<T>&) const;
174  cplx<T> ln () const;
175 
176  cplx<T> sin () const;
177  cplx<T> cos () const;
178  cplx<T> sinh () const;
179  cplx<T> cosh () const;
180 
181  cplx<T> asin () const;
182  cplx<T> acos () const;
183  cplx<T> atan () const;
184  cplx<T> asinh () const;
185  cplx<T> acosh () const;
186  cplx<T> atanh () const;
187  // comparison ops
188 
189  bool operator == (const cplx<T>& c) const { return (re == c.re && im == c.im); }
190  bool operator != (const cplx<T>& c) const { return (re != c.re || im != c.im); }
191  // mathematically undefined ...
192  bool operator > (const cplx<T>& c) const { return fabssqr() > c.fabssqr(); }
193  bool operator >= (const cplx<T>& c) const { return fabssqr() >= c.fabssqr(); }
194  bool operator < (const cplx<T>& c) const { return fabssqr() < c.fabssqr(); }
195  bool operator <= (const cplx<T>& c) const { return fabssqr() <= c.fabssqr(); }
196 
197 
198  // IO
199 
200  //template <typename T>
201  friend STD__ ostream& operator << FGD (STD__ ostream&, const cplx< T >&);
202  //template <typename T>
203  friend STD__ istream& operator >> FGD (STD__ istream&, cplx< T >&);
204 
205 } ;
206 
207 
209 // Declare global functions acting on TBCI::cplx<T> numbers
211 template <typename T>
212 inline TBCI__ cplx<T> sqrt (const TBCI__ cplx<T>& z);
214 
216 
217 template <typename T>
219 {
220  re += a; return *this;
221 }
222 
223 
224 template <typename T>
226 {
227  re += a.re; im += a.im; return *this;
228 }
229 
230 template <typename T>
232 {
233  re -= a; return *this;
234 }
235 
236 
237 template <typename T>
239 {
240  re -= a.re; im -= a.im; return *this;
241 }
242 
243 
244 template <typename T>
246 {
247  re *= a; im *= a; return *this;
248 }
249 
250 
251 template <typename T>
253 {
254  REGISTER const T tmp ALIGN(MIN_ALIGN) = re;
255  re = tmp*a.re - im*a.im;
256  im = tmp*a.im + im*a.re;
257  return *this;
258 }
259 
260 
261 template <typename T>
263 {
264  re /= a; im /= a; return *this;
265 }
266 
267 template <typename T>
269 {
270  REGISTER const T tmp ALIGN(MIN_ALIGN) = re;
271  REGISTER const T den ALIGN(MIN_ALIGN) = (a.re*a.re + a.im*a.im);
272 
273  re = (tmp*a.re + im*a.im) / den;
274  im = (im*a.re - tmp*a.im) / den;
275  return *this;
276 }
277 
278 
279 template <typename T>
280 inline cplx<T> cplx<T>::operator + (const cplx<T>& a) const
281 {
282  return cplx<T> (re + a.re, im + a.im);
283 }
284 
285 
286 template <typename T>
287 inline cplx<T> cplx<T>::operator - (const cplx<T>& a) const
288 {
289  return cplx<T> (re - a.re, im - a.im);
290 }
291 
292 
293 template <typename T>
294 inline cplx<T> cplx<T>::operator * (const cplx<T>& a) const
295 {
296  return cplx<T>( re*a.re - im*a.im, im*a.re + re*a.im );
297 }
298 
299 template <typename T>
300 inline cplx<T> dot (const cplx<T>& a, const cplx<T>& b)
301 {
302  return cplx<T> (a.re*b.re + a.im*b.im, a.re*b.im - a.im*b.re);
303 
304 }
305 
306 template <typename T>
307 inline cplx<T> cplx<T>::operator / (const cplx<T>& a) const
308 {
309  REGISTER const T den ALIGN(MIN_ALIGN) = (T)1 / (a.re*a.re + a.im*a.im);
310  // T den ( (T)1 / (a.re*a.re + a.im*a.im) );
311  return cplx<T>( ( re*a.re + im*a.im ) * den, ( im*a.re - re*a.im ) * den );
312 }
313 
314 
315 INST(template <typename T> class cplx friend cplx<T> operator + (const T, const cplx<T>&);)
316 template <typename T>
317 inline cplx<T> operator + (const T a, const cplx<T>& b)
318 { return b.plus (a); }
319 
320 
321 INST(template <typename T> class cplx friend cplx<T> operator - (const T, const cplx<T>&);)
322 template <typename T>
323 inline cplx<T> operator - (const T a, const cplx<T>& b)
324 { return b.minus (a); }
325 
326 
327 #if 0
328 template <typename T, typename U>
329 cplx<T> operator * (const U f, const cplx<T>& c)
330 { return cplx<T> (f*c.real(), f*c.imag()); }
331 #endif
332 
333 
334 INST(template <typename T> class cplx friend cplx<T> operator * (const T, const cplx<T>&);)
335 template <typename T>
336 inline cplx<T> operator * (const T a, const cplx<T>& b)
337 { return b.mult (a); }
338 
339 
340 INST(template <typename T> class cplx friend cplx<T> operator / (const T, const cplx<T>&);)
341 template <typename T>
342 inline cplx<T> operator / (const T a, const cplx<T>& b)
343 { return b.div (a); }
344 
345 
346 template <typename T>
347 inline cplx<T> cplx<T>::operator + (const T b) const
348 {
349  return cplx<T> (re + b, im);
350 }
351 
352 
353 template <typename T>
354 inline cplx<T> cplx<T>::operator - (const T b) const
355 {
356  return cplx<T> (re - b, im);
357 }
358 
359 
360 template <typename T>
361 inline cplx<T> cplx<T>::operator * (const T b) const
362 {
363  return cplx<T> (re * b, im * b);
364 }
365 
366 
367 template <typename T>
368 inline cplx<T> cplx<T>::operator / (const T b) const
369 {
370  return cplx<T> (re / b, im / b);
371 }
372 
373 
374 template <typename T>
376 {
377  return cplx<T> (-re, -im);
378 }
379 
380 
381 template <typename T>
383 {
384  return cplx<T> (re, -im);
385 }
386 
387 
388 INST(template <typename T> class cplx friend double fabssqr (const cplx<T>&);)
389 template <typename T>
390 inline double fabssqr(const cplx<T>& c)
391 { return c.fabssqr(); }
392 
393 
394 template <typename T>
395 inline double cplx<T>::fabs () const
396 {
397  // return sqrt (fabssqr (c));
398  // numerically superior variant:
399  if (UNLIKELY(im != 0)) {
401  return (GLBL__ MATH__ fabs(im) * GLBL__ MATH__ sqrt(1.0+(double)re*re/(im*im)) );
402  else /*if (LIKELY(re != 0))*/
403  return (GLBL__ MATH__ fabs(re) * GLBL__ MATH__ sqrt(1.0+(double)im*im/(re*re)) );
404  // else abort(); //Strange things going on!
405  } else
406  return (GLBL__ MATH__ fabs(re));
407 }
408 
409 
410 template <typename T>
411 inline T cplx<T>::abs () const
412 {
413  // return sqrt (fabssqr (c));
414  // numerically superior
415  if (UNLIKELY(im != 0)) {
416  if (UNLIKELY(GLBL__ CSTD__ abs(im) > GLBL__ CSTD__ abs(re)))
417  return (GLBL__ CSTD__ abs(im) * GLBL__ MATH__ sqrt(1+re*re/(im*im)) );
418  else /*if (LIKELY(re != 0))*/
419  return (GLBL__ CSTD__ abs(re) * GLBL__ MATH__ sqrt(1+im*im/(re*re)) );
420  // else abort(); //Strange things going on!
421  } else
422  return (GLBL__ CSTD__ abs(re));
423 }
424 
425 
426 template <typename T>
428 {
429  //const static double halfpi = 0.5*pi;
430  if (UNLIKELY(re == 0)) {
431  if (LIKELY(im > 0))
432  return 0.5*pi;
433  else if (LIKELY(im < 0))
434  return -0.5*pi;
435  else
436  return 0;
437  }
438 
439  //if (c.im >= 0) return atan2 (c.im, c.re); // no negative phases
440  //else return 2*pi + atan2 (c.im, c.re);
441  if (UNLIKELY(im == 0.0))
442  return atan2 (0.0, re); // dirty workaround (JLT)
443  else
444  return atan2 (im, re); // allow for negtive phases
445 }
446 
447 INST(template <typename T> class TBCI__ cplx friend cplx<T> sqr (const cplx<T>&);)
448 template <typename T>
449 inline cplx<T> sqr (const cplx<T>& c)
450 {
451  // return fabssqr (c) * expi ((T)2 * c.theta());
452  REGISTER const T re(c.real()), im(c.imag());
453  // FIXME: Shouldn't this work:
454  // return cplx<T> (sqr(re) - sqr(im), 2*re*im);
455  return cplx<T> (re*re - im*im, 2*re*im);
456 }
457 
458 INST(template <typename T> class TBCI__ cplx friend cplx<T> expi (const T);)
459 template <typename T>
460 cplx<T> expi (const T phi)
461 {
462  const REGISTER T tmp ALIGN(MIN_ALIGN) = MATH__ fmod (phi, 2*pi);
463  return cplx<T> (MATH__ cos(tmp), MATH__ sin(tmp));
464 }
465 
466 template <typename T>
468 {
469  return GLBL__ MATH__ sqrt (fabs()) * TBCI__ expi ((double)(0.5) * theta());
470 }
471 
472 template <typename T>
473 inline cplx<T> cplx<T>::exp () const
474 {
475  return GLBL__ MATH__ exp ((double)(this->real())) * TBCI__ expi(this->imag());
476 }
477 
478 template <typename T>
479 inline cplx<T> cplx<T>::power (const double n) const
480 {
481  return GLBL__ MATH__ pow (this->fabs(), n) * TBCI__ expi (n*this->theta());
482 }
483 
484 template <typename T>
486 {
487  const double lnt = GLBL__ MATH__ log (fabs());
488  const T phi = theta();
489  return GLBL__ MATH__ exp (lnt*z.re - phi*z.im) * expi (phi*z.re + lnt*z.im);
490 }
491 
492 template <typename T>
493 inline cplx<T> cplx<T>::ln () const
494 {
495  return cplx<T>(GLBL__ MATH__ log (fabs()), theta());
496 }
497 
498 template <typename T>
500 {
501  const cplx<T> zi = cplx<T> (-im, re);
502  return cplx<T>(0.0,-0.5) * (zi.exp() - (-zi).exp());
503 }
504 
505 template <typename T>
507 {
508  const cplx<T> zi = cplx<T> (-im, re);
509  return 0.5 * (zi.exp() + (-zi).exp());
510 }
511 
512 template <typename T>
514 {
515  return 0.5 * (exp() - (-(*this)).exp());
516 }
517 
518 template <typename T>
520 {
521  return 0.5 * (exp() + (-(*this)).exp());
522 }
523 
524 template <typename T>
526 {
527  const cplx<T> arg = cplx<T>(-im, re) + GLBL__ MATH__ sqrt (1.0 - sqr(*this));
528  return cplx<T>(0.0,-1.0) * arg.ln();
529 }
530 
531 template <typename T>
533 {
534  const cplx<T> arg = *this + GLBL__ MATH__ sqrt (sqr(*this) - 1.0);
535  return cplx<T>(0.0,-1.0) * arg.ln();
536 }
537 
538 template <typename T>
540 {
541  const cplx<T> arg = *this + GLBL__ MATH__ sqrt (sqr(*this) + 1.0);
542  return arg.ln();
543 }
544 
545 template <typename T>
547 {
548  const cplx<T> arg = *this + GLBL__ MATH__ sqrt (sqr(*this) - 1.0);
549  return arg.ln();
550 }
551 
552 template <typename T>
554 {
555  const cplx<T> arg = (1.0 + cplx<T>(-im,re)) / ( 1.0 - cplx<T>(-im,re));
556  return cplx<T>(0.0,-0.5) * arg.ln();
557 }
558 
559 template <typename T>
561 {
562  const cplx<T> arg = (1.0 + *this) / (1.0 - *this);
563  return 0.5 * arg.ln();
564 }
565 
566 
567 #ifdef TBCI_CPLX_OLD_IOFMT
568 template <typename T> STD__ ostream& operator << (STD__ ostream& os, const cplx<T>& c)
569 {
570  os << "( " << c.re;
571  if (c.im < 0)
572  os << " - i " << -c.im;
573  else
574  os << " + i " << c.im;
575  os << " )";
576  return os;
577 }
578 
579 /*
580 template <typename T>
581 STD__ ofstream& operator << (STD__ ofstream& os, const cplx<T>& c)
582 {
583  os.operator<<(c.re);
584  os << " ";
585  os.operator<<(c.im);
586  return os;
587 }
588 */
589 
590 template <typename T>
591 STD__ istream& operator >> (STD__ istream& in, cplx<T>& c)
592 {
593  T r, i;
594  char s = '+', b = 'i', bra = '(';
595 
596  if (! (in >> bra))
597  return in;
598  if (bra != '(') in.putback(bra);
599  if (! (in >> r))
600  return in;
601  in >> s;
602  if ((s != '+') && (s != '-')) in.putback(s);
603  in >> b;
604  if ((b != 'i')) in.putback(b);
605  if (! (in >> i))
606  return in;
607  c.re = r;
608  if (s == '-') c.im =- i;
609  else c.im = i;
610  if (bra == '(')
611  {
612  if (! (in >> bra))
613  return in;
614  if (bra != ')') in.putback(bra);
615  }
616  return in;
617 }
618 
619 #else /* TBCI_CPLX_OLD_IOFMT */
620 
621 template <typename T> STD__ ostream& operator << (STD__ ostream& os, const cplx<T>& c)
622 {
623  return os << "(" << c.re << "," << c.im << ")";
624 }
625 
626 template <typename T>
627 STD__ istream& operator >> (STD__ istream& in, cplx<T>& c)
628 {
629  T r ALIGN(MIN_ALIGN), i = (T)0;
630  char bra;
631 
632  if (! (in >> bra))
633  return in;
634  if (bra != '(') {
635  in.putback(bra);
636  if (in >> r) {
637  c.re = r; c.im = (T)0;
638  }
639  return in;
640  }
641  if (!(in >> r))
642  return in;
643  in >> bra;
644  c.re = r; c.im = (T)0;
645  if (bra != ',')
646  return in;
647  if (! (in >> i))
648  return in;
649  c.im = i;
650  in >> bra;
651  if (bra != ')')
652  /* error */;
653  return in;
654 }
655 
656 #endif /* TBCI_CPLX_OLD_IOFMT */
657 
660 
661 INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> conj (const TBCI__ cplx<T>&);)
662 template <typename T>
663 inline TBCI__ cplx<T> conj (const TBCI__ cplx<T>& c)
664 { return c.conj(); }
665 
666 
667 // member access (read-only)
668 INST(template <typename T> class TBCI__ cplx friend T real (const TBCI__ cplx<T>&);)
669 INST(template <typename T> class TBCI__ cplx friend T imag (const TBCI__ cplx<T>&);)
670 template <typename T>
671 inline T real (const TBCI__ cplx<T>& z)
672 { return z.real(); }
673 template <typename T>
674 inline T imag (const TBCI__ cplx<T>& z)
675 { return z.imag(); }
676 
677 // member access (read-write)
678 INST(template <typename T> class TBCI__ cplx friend T& real (TBCI__ cplx<T>&);)
679 INST(template <typename T> class TBCI__ cplx friend T& imag (TBCI__ cplx<T>&);)
680 template <typename T>
681 inline T& real (TBCI__ cplx<T>& z)
682 { return z.real(); }
683 template <typename T>
684 inline T& imag (TBCI__ cplx<T>& z)
685 { return z.imag(); }
686 
687 
688 INST(template <typename T> class TBCI__ cplx friend T arg (const TBCI__ cplx<T>&);)
689 template <typename T>
690 inline T arg (const TBCI__ cplx<T>& c)
691 { return c.theta(); }
692 
693 INST(template <typename T> class TBCI__ cplx friend double norm (const TBCI__ cplx<T>&);)
694 template <typename T>
695 inline double norm (const TBCI__ cplx<T>& c)
696 { return c.norm(); }
697 
698 // Trouble is: polar() conflicts with the std decl
699 
702 
703 #ifndef NO_NS
704 INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> polar (const T&, const T&);)
705 template <typename T>
706 inline TBCI__ cplx<T> polar (const T& r, const T& p)
707 { return r * TBCI__ expi (p); }
708 #else
709 INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> _polar (const T&, const T&);)
710 template <typename T>
711 inline TBCI__ cplx<T> _polar (const T& r, const T& p)
712 { return r * TBCI__ expi (p); }
713 #endif
714 
715 #if defined(__i386__) && defined(__GNUC__) && defined(USE_ASM) && defined(CPLX_ASM) && !defined(NO_DOUBLE_SPEC)
716 template <>
718 {
719  REGISTER double r, i;
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"
722  : "=u" (r), "=t" (i)
723  : "g" (re), "g" (im), "m" (a.re), "m" (a.im)
724  : "st(6)", "st(7)" );
725  return cplx<double> (r, i);
726 }
727 #endif
728 
729 #ifdef NEED_IMAG_UNIT
730 const cplx<double> Imag_unit (0.0, 1.0);
731 #endif
732 
734 
735 
737 
738 // should abs be in CPLX__ rather than CSTD__ ?
739 INST(template <typename T> class TBCI__ cplx friend T abs (const TBCI__ cplx<T>&);)
740 template <typename T>
741 inline T abs (const TBCI__ cplx<T>& c)
742 { return c.abs(); }
743 
744 INST(template <typename T> class TBCI__ cplx friend double fabs (const TBCI__ cplx<T>&);)
745 template <typename T>
746 inline double fabs (const TBCI__ cplx<T>& c)
747 { return c.fabs(); }
748 
749 INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> sqrt (const TBCI__ cplx<T>&);)
750 template <typename T>
751 inline TBCI__ cplx<T> sqrt (const TBCI__ cplx<T>& z)
752 { return z.sqrt(); }
753 
754 INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> exp (const TBCI__ cplx<T>&);)
755 template <typename T>
756 inline TBCI__ cplx<T> exp (const TBCI__ cplx<T>& z)
757 { return z.exp (); }
758 
759 INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> pow (const TBCI__ cplx<T>&, const double);)
760 template <typename T>
761 inline TBCI__ cplx<T> pow (const TBCI__ cplx<T>& z, const double n)
762 { return z.power (n); }
763 
764 INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> pow (const TBCI__ cplx<T>&, const TBCI__ cplx<T>&);)
765 template <typename T>
766 inline TBCI__ cplx<T> pow (const TBCI__ cplx<T>& z, const TBCI__ cplx<T>& x)
767 { return z.power (x); }
768 
769 INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> log (const TBCI__ cplx<T>&);)
770 template <typename T>
771 inline TBCI__ cplx<T> log (const TBCI__ cplx<T>& z)
772 { return z.ln(); }
773 
774 INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> sin (const TBCI__ cplx<T>&);)
775 template <typename T>
776 inline TBCI__ cplx<T> sin (const TBCI__ cplx<T>& z)
777 { return z.sin(); }
778 
779 INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> sinh (const TBCI__ cplx<T>&);)
780 template <typename T>
781 inline TBCI__ cplx<T> sinh (const TBCI__ cplx<T>& z)
782 { return z.sinh(); }
783 
784 INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> cos (const TBCI__ cplx<T>&);)
785 template <typename T>
786 inline TBCI__ cplx<T> cos (const TBCI__ cplx<T>& z)
787 { return z.cos(); }
788 
789 INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> cosh (const TBCI__ cplx<T>&);)
790 template <typename T>
791 inline TBCI__ cplx<T> cosh (const TBCI__ cplx<T>& z)
792 { return z.cosh(); }
793 
794 INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> tan (const TBCI__ cplx<T>&);)
795 template <typename T>
796 inline TBCI__ cplx<T> tan (const TBCI__ cplx<T>& z)
797 { return z.sin()/z.cos(); }
798 
799 INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> tanh (const TBCI__ cplx<T>&);)
800 template <typename T>
801 inline TBCI__ cplx<T> tanh (const TBCI__ cplx<T>& z)
802 { return z.sinh()/z.cosh(); }
803 
804 INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> asin (const TBCI__ cplx<T>&);)
805 template <typename T>
806 inline TBCI__ cplx<T> asin (const TBCI__ cplx<T>& z)
807 { return z.asin(); }
808 
809 INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> asinh (const TBCI__ cplx<T>&);)
810 template <typename T>
811 inline TBCI__ cplx<T> asinh (const TBCI__ cplx<T>& z)
812 { return z.asinh(); }
813 
814 INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> acos (const TBCI__ cplx<T>&);)
815 template <typename T>
816 inline TBCI__ cplx<T> acos (const TBCI__ cplx<T>& z)
817 { return z.acos(); }
818 
819 INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> acosh (const TBCI__ cplx<T>&);)
820 template <typename T>
821 inline TBCI__ cplx<T> acosh (const TBCI__ cplx<T>& z)
822 { return z.acosh(); }
823 
824 INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> atan (const TBCI__ cplx<T>&);)
825 template <typename T>
826 inline TBCI__ cplx<T> atan (const TBCI__ cplx<T>& z)
827 { return z.atan(); }
828 
829 INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> atanh (const TBCI__ cplx<T>&);)
830 template <typename T>
831 inline TBCI__ cplx<T> atanh (const TBCI__ cplx<T>& z)
832 { return z.atanh(); }
833 
834 INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> log10 (const TBCI__ cplx<T>&);)
835 template <typename T>
836 inline TBCI__ cplx<T> log10 (const TBCI__ cplx<T>& z)
837 { const static double InvLn10 = (1.0 / log(10.0));
838  return z.ln()*InvLn10;
839 }
840 
842 
843 /* Provide specialized memory allocators for cplx<> types */
844 # include "cplx_memalloc.h"
845 
847 /* If used in loops, a single copy is still cheaper than pointer
848  * indirection */
853 
855 
856 #endif /* TBCI_CPLX_H */
857 
cplx< T > div(const T a) const
Definition: cplx.h:137
T theta() const
Definition: cplx.h:427
TBCI__ cplx< T > asin(const TBCI__ cplx< T > &z)
Definition: cplx.h:806
const Vector< T > const Vector< T > & x
Definition: LM_fit.h:97
cplx< T > asin() const
Definition: cplx.h:525
T imag() const
Definition: cplx.h:107
#define MIN_ALIGN
Definition: basics.h:421
#define ALIGN(x)
Definition: basics.h:444
const Vector< T > const Vector< T > const Vector< T > & p
Definition: LM_fit.h:97
double fabs() const
Definition: cplx.h:395
TBCI__ cplx< T > tan(const TBCI__ cplx< T > &z)
Definition: cplx.h:796
bool operator>=(const cplx< T > &c) const
Definition: cplx.h:193
cplx< T > cplx_t
Definition: cplx.h:68
STD__ istream & operator>>(STD__ istream &istr, BdMatrix< T > &mat)
Definition: band_matrix.h:2739
TBCI__ cplx< T > log(const TBCI__ cplx< T > &z)
Definition: cplx.h:771
T re ALIGN(MIN_ALIGN)
Our own complex class.
Definition: cplx.h:48
#define REGISTER
Definition: basics.h:108
return c
Definition: f_matrix.h:760
TBCI__ cplx< T > cos(const TBCI__ cplx< T > &z)
Definition: cplx.h:786
double fabs(const int a)
Definition: basics.h:1215
#define NAMESPACE_TBCI
Definition: basics.h:317
double atan2(const double, const double)
~cplx()
Definition: cplx.h:85
#define SPEC_TBCI_TRAITS_ALWAYS_COPY(TYPE)
Definition: tbci_traits.h:56
cplx< T > & do_conj()
Definition: cplx.h:162
cplx< T > plus(const T v) const
Definition: cplx.h:127
cplx< T > operator*(const cplx< T > &) const
Definition: cplx.h:294
cplx< T > operator-() const
Definition: cplx.h:375
cplx< T > & operator-=(const T)
Definition: cplx.h:231
cplx< T > operator/(const cplx< T > &) const
Definition: cplx.h:307
TBCI__ cplx< T > atan(const TBCI__ cplx< T > &z)
Definition: cplx.h:826
cplx< T > acos() const
Definition: cplx.h:532
T real() const
Definition: cplx.h:106
cplx< T > cos() const
Definition: cplx.h:506
#define NAMESPACE_CSTD_END
Definition: basics.h:325
#define UNLIKELY(expr)
Definition: basics.h:101
#define SPEC_TBCI_TRAITS_LOOP_COPY(TYPE)
Definition: tbci_traits.h:71
TBCI__ cplx< T > atanh(const TBCI__ cplx< T > &z)
Definition: cplx.h:831
cplx()
Definition: cplx.h:71
cplx(const T r, const T i=(T) 0)
Definition: cplx.h:72
cplx< T > expi(const T phi)
Definition: cplx.h:460
cplx< T > asinh() const
Definition: cplx.h:539
double fabssqr() const
Definition: cplx.h:164
double norm() const
Definition: cplx.h:166
const Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > & z
Definition: LM_fit.h:172
TBCI__ cplx< T > log10(const TBCI__ cplx< T > &z)
Definition: cplx.h:836
T & real()
Definition: cplx.h:109
T arg(const TBCI__ cplx< T > &c)
Definition: cplx.h:690
cplx< T > sinh() const
Definition: cplx.h:513
TBCI__ cplx< T > tanh(const TBCI__ cplx< T > &z)
Definition: cplx.h:801
cplx(const cplx< T > &c)
Definition: cplx.h:73
cplx< T > ln() const
Definition: cplx.h:493
#define NAMESPACE_CPLX
Definition: basics.h:322
TBCI__ cplx< T > acosh(const TBCI__ cplx< T > &z)
Definition: cplx.h:821
bool operator!=(const cplx< T > &c) const
Definition: cplx.h:190
const double pi
Definition: constants.h:38
cplx< T > operator+(const cplx< T > &) const
Definition: cplx.h:280
double sqrt(const int a)
Definition: basics.h:1216
cplx< T > atan() const
Definition: cplx.h:553
T & imag()
Definition: cplx.h:110
cplx(const cplx< U > &c)
Definition: cplx.h:79
#define U
Definition: bdmatlib.cc:21
#define CSTD__
Definition: basics.h:340
cplx< T > sqr(const cplx< T > &c)
Definition: cplx.h:449
T re im
Definition: cplx.h:61
T abs() const
Definition: cplx.h:411
cplx< T > sqrt() const
Definition: cplx.h:467
cplx< T > conj() const
Definition: cplx.h:158
cplx< T > & operator/=(const T)
Definition: cplx.h:262
#define TBCI__
Definition: basics.h:332
cplx< T > acosh() const
Definition: cplx.h:546
TBCI__ cplx< T > sin(const TBCI__ cplx< T > &z)
Definition: cplx.h:776
T value_type
Definition: cplx.h:65
F_TMatrix< T > b
Definition: f_matrix.h:736
#define GLBL__
Definition: basics.h:342
cplx< T > & operator=(const T r)
Definition: cplx.h:89
cplx< T > operator~() const
Definition: cplx.h:382
TBCI__ cplx< T > exp(const TBCI__ cplx< T > &z)
Definition: cplx.h:756
BdMatrix< T > operator*(const T &v, const BdMatrix< T > &m)
Definition: band_matrix.h:1449
bool operator>(const cplx< T > &c) const
Definition: cplx.h:192
int conj(const int arg)
conj for elementary types
Definition: basics.h:1055
#define NAMESPACE_CSTD
Definition: basics.h:319
cplx< T > & operator*=(const T)
Definition: cplx.h:245
cplx< T > atanh() const
Definition: cplx.h:560
T cplx_base
Definition: cplx.h:67
cplx< T > sin() const
Definition: cplx.h:499
#define INST(x)
Definition: basics.h:238
T dot(const T &a1, const T &a2)
Definition: basics.h:1183
int i
Definition: LM_fit.h:71
#define real
#define NAMESPACE_CPLX_END
Definition: basics.h:326
cplx< T > & operator+=(const T)
Definition: cplx.h:218
TBCI__ cplx< T > asinh(const TBCI__ cplx< T > &z)
Definition: cplx.h:811
cplx< T > minus(const T v) const
Definition: cplx.h:130
#define STD__
Definition: basics.h:338
cplx< T > & set(const T r, const T i)
Definition: cplx.h:104
T aligned_value_type TALIGN(MIN_ALIGN)
Definition: cplx.h:66
#define abs(x)
Definition: f2c.h:178
#define NAMESPACE_END
Definition: basics.h:323
float real
Definition: f2c.h:31
double fabssqr(const double a)
Definition: basics.h:1157
cplx< T > exp() const
Definition: cplx.h:473
#define T
Definition: bdmatlib.cc:20
double norm(const TBCI__ cplx< T > &c)
Definition: cplx.h:695
TBCI__ cplx< T > sinh(const TBCI__ cplx< T > &z)
Definition: cplx.h:781
const unsigned TMatrix< T > const Matrix< T > * a
cplx< T > mult(const T v) const
Definition: cplx.h:133
const Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > long int int char v
&lt; find minimun of func on grid with resolution res
Definition: LM_fit.h:205
TBCI__ cplx< T > pow(const TBCI__ cplx< T > &z, const double n)
Definition: cplx.h:761
TBCI__ cplx< T > cosh(const TBCI__ cplx< T > &z)
Definition: cplx.h:791
#define MATH__
Definition: basics.h:339
TBCI__ cplx< T > acos(const TBCI__ cplx< T > &z)
Definition: cplx.h:816
bool operator==(const cplx< T > &c) const
Definition: cplx.h:189
#define LIKELY(expr)
branch prediction note that we sometimes on purpose mark the unlikely possibility likely and vice ver...
Definition: basics.h:100
friend cplx< T > dot FGD(const cplx< T > &, const cplx< T > &)
cplx< T > cosh() const
Definition: cplx.h:519
int imag(const int d)
Definition: basics.h:1068
cplx< T > power(const double) const
Definition: cplx.h:479
NAMESPACE_CPLX_END NAMESPACE_TBCI TBCI__ cplx< T > polar(const T &r, const T &p)
Definition: cplx.h:706