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
48template <typename T> class cplx;
49
53
54template <typename T>
55class 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);
96 cplx<T>& operator -= (const T);
98 cplx<T>& operator *= (const T);
100 cplx<T>& operator /= (const 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
211template <typename T>
212inline TBCI__ cplx<T> sqrt (const TBCI__ cplx<T>& z);
214
216
217template <typename T>
219{
220 re += a; return *this;
221}
222
223
224template <typename T>
226{
227 re += a.re; im += a.im; return *this;
228}
229
230template <typename T>
232{
233 re -= a; return *this;
234}
235
236
237template <typename T>
239{
240 re -= a.re; im -= a.im; return *this;
241}
242
243
244template <typename T>
246{
247 re *= a; im *= a; return *this;
248}
249
250
251template <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
261template <typename T>
263{
264 re /= a; im /= a; return *this;
265}
266
267template <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
279template <typename T>
281{
282 return cplx<T> (re + a.re, im + a.im);
283}
284
285
286template <typename T>
288{
289 return cplx<T> (re - a.re, im - a.im);
290}
291
292
293template <typename T>
295{
296 return cplx<T>( re*a.re - im*a.im, im*a.re + re*a.im );
297}
298
299template <typename T>
300inline 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
306template <typename T>
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
315INST(template <typename T> class cplx friend cplx<T> operator + (const T, const cplx<T>&);)
316template <typename T>
317inline cplx<T> operator + (const T a, const cplx<T>& b)
318{ return b.plus (a); }
319
320
321INST(template <typename T> class cplx friend cplx<T> operator - (const T, const cplx<T>&);)
322template <typename T>
323inline cplx<T> operator - (const T a, const cplx<T>& b)
324{ return b.minus (a); }
325
326
327#if 0
328template <typename T, typename U>
329cplx<T> operator * (const U f, const cplx<T>& c)
330{ return cplx<T> (f*c.real(), f*c.imag()); }
331#endif
332
333
334INST(template <typename T> class cplx friend cplx<T> operator * (const T, const cplx<T>&);)
335template <typename T>
336inline cplx<T> operator * (const T a, const cplx<T>& b)
337{ return b.mult (a); }
338
339
340INST(template <typename T> class cplx friend cplx<T> operator / (const T, const cplx<T>&);)
341template <typename T>
342inline cplx<T> operator / (const T a, const cplx<T>& b)
343{ return b.div (a); }
344
345
346template <typename T>
347inline cplx<T> cplx<T>::operator + (const T b) const
348{
349 return cplx<T> (re + b, im);
350}
351
352
353template <typename T>
354inline cplx<T> cplx<T>::operator - (const T b) const
355{
356 return cplx<T> (re - b, im);
357}
358
359
360template <typename T>
361inline cplx<T> cplx<T>::operator * (const T b) const
362{
363 return cplx<T> (re * b, im * b);
364}
365
366
367template <typename T>
368inline cplx<T> cplx<T>::operator / (const T b) const
369{
370 return cplx<T> (re / b, im / b);
371}
372
373
374template <typename T>
376{
377 return cplx<T> (-re, -im);
378}
379
380
381template <typename T>
383{
384 return cplx<T> (re, -im);
385}
386
387
388INST(template <typename T> class cplx friend double fabssqr (const cplx<T>&);)
389template <typename T>
390inline double fabssqr(const cplx<T>& c)
391{ return c.fabssqr(); }
392
393
394template <typename T>
395inline 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
410template <typename T>
411inline T cplx<T>::abs () const
412{
413 // return sqrt (fabssqr (c));
414 // numerically superior
415 if (UNLIKELY(im != 0)) {
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
426template <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
447INST(template <typename T> class TBCI__ cplx friend cplx<T> sqr (const cplx<T>&);)
448template <typename T>
449inline 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
458INST(template <typename T> class TBCI__ cplx friend cplx<T> expi (const T);)
459template <typename T>
460cplx<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
466template <typename T>
468{
469 return GLBL__ MATH__ sqrt (fabs()) * TBCI__ expi ((double)(0.5) * theta());
470}
471
472template <typename T>
473inline cplx<T> cplx<T>::exp () const
474{
475 return GLBL__ MATH__ exp ((double)(this->real())) * TBCI__ expi(this->imag());
476}
477
478template <typename T>
479inline 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
484template <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
492template <typename T>
493inline cplx<T> cplx<T>::ln () const
494{
495 return cplx<T>(GLBL__ MATH__ log (fabs()), theta());
496}
497
498template <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
505template <typename T>
507{
508 const cplx<T> zi = cplx<T> (-im, re);
509 return 0.5 * (zi.exp() + (-zi).exp());
510}
511
512template <typename T>
514{
515 return 0.5 * (exp() - (-(*this)).exp());
516}
517
518template <typename T>
520{
521 return 0.5 * (exp() + (-(*this)).exp());
522}
523
524template <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
531template <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
538template <typename T>
540{
541 const cplx<T> arg = *this + GLBL__ MATH__ sqrt (sqr(*this) + 1.0);
542 return arg.ln();
543}
544
545template <typename T>
547{
548 const cplx<T> arg = *this + GLBL__ MATH__ sqrt (sqr(*this) - 1.0);
549 return arg.ln();
550}
551
552template <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
559template <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
568template <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/*
580template <typename T>
581STD__ 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
590template <typename T>
591STD__ 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
621template <typename T> STD__ ostream& operator << (STD__ ostream& os, const cplx<T>& c)
622{
623 return os << "(" << c.re << "," << c.im << ")";
624}
625
626template <typename T>
627STD__ 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
661INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> conj (const TBCI__ cplx<T>&);)
662template <typename T>
664{ return c.conj(); }
665
666
667// member access (read-only)
668INST(template <typename T> class TBCI__ cplx friend T real (const TBCI__ cplx<T>&);)
669INST(template <typename T> class TBCI__ cplx friend T imag (const TBCI__ cplx<T>&);)
670template <typename T>
671inline T real (const TBCI__ cplx<T>& z)
672{ return z.real(); }
673template <typename T>
674inline T imag (const TBCI__ cplx<T>& z)
675{ return z.imag(); }
676
677// member access (read-write)
678INST(template <typename T> class TBCI__ cplx friend T& real (TBCI__ cplx<T>&);)
679INST(template <typename T> class TBCI__ cplx friend T& imag (TBCI__ cplx<T>&);)
680template <typename T>
681inline T& real (TBCI__ cplx<T>& z)
682{ return z.real(); }
683template <typename T>
684inline T& imag (TBCI__ cplx<T>& z)
685{ return z.imag(); }
686
687
688INST(template <typename T> class TBCI__ cplx friend T arg (const TBCI__ cplx<T>&);)
689template <typename T>
690inline T arg (const TBCI__ cplx<T>& c)
691{ return c.theta(); }
692
693INST(template <typename T> class TBCI__ cplx friend double norm (const TBCI__ cplx<T>&);)
694template <typename T>
695inline 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
704INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> polar (const T&, const T&);)
705template <typename T>
706inline TBCI__ cplx<T> polar (const T& r, const T& p)
707{ return r * TBCI__ expi (p); }
708#else
709INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> _polar (const T&, const T&);)
710template <typename T>
711inline 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)
716template <>
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
730const cplx<double> Imag_unit (0.0, 1.0);
731#endif
732
734
735
737
738// should abs be in CPLX__ rather than CSTD__ ?
739INST(template <typename T> class TBCI__ cplx friend T abs (const TBCI__ cplx<T>&);)
740template <typename T>
741inline T abs (const TBCI__ cplx<T>& c)
742{ return c.abs(); }
743
744INST(template <typename T> class TBCI__ cplx friend double fabs (const TBCI__ cplx<T>&);)
745template <typename T>
746inline double fabs (const TBCI__ cplx<T>& c)
747{ return c.fabs(); }
748
749INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> sqrt (const TBCI__ cplx<T>&);)
750template <typename T>
752{ return z.sqrt(); }
753
754INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> exp (const TBCI__ cplx<T>&);)
755template <typename T>
756inline TBCI__ cplx<T> exp (const TBCI__ cplx<T>& z)
757{ return z.exp (); }
758
759INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> pow (const TBCI__ cplx<T>&, const double);)
760template <typename T>
761inline TBCI__ cplx<T> pow (const TBCI__ cplx<T>& z, const double n)
762{ return z.power (n); }
763
764INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> pow (const TBCI__ cplx<T>&, const TBCI__ cplx<T>&);)
765template <typename T>
766inline TBCI__ cplx<T> pow (const TBCI__ cplx<T>& z, const TBCI__ cplx<T>& x)
767{ return z.power (x); }
768
769INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> log (const TBCI__ cplx<T>&);)
770template <typename T>
771inline TBCI__ cplx<T> log (const TBCI__ cplx<T>& z)
772{ return z.ln(); }
773
774INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> sin (const TBCI__ cplx<T>&);)
775template <typename T>
776inline TBCI__ cplx<T> sin (const TBCI__ cplx<T>& z)
777{ return z.sin(); }
778
779INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> sinh (const TBCI__ cplx<T>&);)
780template <typename T>
782{ return z.sinh(); }
783
784INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> cos (const TBCI__ cplx<T>&);)
785template <typename T>
786inline TBCI__ cplx<T> cos (const TBCI__ cplx<T>& z)
787{ return z.cos(); }
788
789INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> cosh (const TBCI__ cplx<T>&);)
790template <typename T>
792{ return z.cosh(); }
793
794INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> tan (const TBCI__ cplx<T>&);)
795template <typename T>
796inline TBCI__ cplx<T> tan (const TBCI__ cplx<T>& z)
797{ return z.sin()/z.cos(); }
798
799INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> tanh (const TBCI__ cplx<T>&);)
800template <typename T>
802{ return z.sinh()/z.cosh(); }
803
804INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> asin (const TBCI__ cplx<T>&);)
805template <typename T>
807{ return z.asin(); }
808
809INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> asinh (const TBCI__ cplx<T>&);)
810template <typename T>
812{ return z.asinh(); }
813
814INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> acos (const TBCI__ cplx<T>&);)
815template <typename T>
817{ return z.acos(); }
818
819INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> acosh (const TBCI__ cplx<T>&);)
820template <typename T>
822{ return z.acosh(); }
823
824INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> atan (const TBCI__ cplx<T>&);)
825template <typename T>
827{ return z.atan(); }
828
829INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> atanh (const TBCI__ cplx<T>&);)
830template <typename T>
832{ return z.atanh(); }
833
834INST(template <typename T> class TBCI__ cplx friend TBCI__ cplx<T> log10 (const TBCI__ cplx<T>&);)
835template <typename T>
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
const Vector< T > const Vector< T > const Vector< T > & p
Definition LM_fit.h:98
const Vector< T > const Vector< T > & x
Definition LM_fit.h:97
int i
Definition LM_fit.h:71
#define CSTD__
Definition basics.h:340
#define STD__
Definition basics.h:338
#define LIKELY(expr)
branch prediction note that we sometimes on purpose mark the unlikely possibility likely and vice ver...
Definition basics.h:100
#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 UNLIKELY(expr)
Definition basics.h:101
#define REGISTER
Definition basics.h:108
#define MATH__
Definition basics.h:339
#define GLBL__
Definition basics.h:342
#define ALIGN(x)
Definition basics.h:444
#define NAMESPACE_CPLX
Definition basics.h:322
#define MIN_ALIGN
Definition basics.h:421
#define FGD
Definition basics.h:144
#define T
Definition bdmatlib.cc:20
#define U
Definition bdmatlib.cc:21
Our own complex class.
Definition cplx.h:56
cplx< T > & set(const T r, const T i)
Definition cplx.h:104
cplx< T > & operator-=(const T)
Definition cplx.h:231
cplx< T > atan() const
Definition cplx.h:553
friend class cplx
Definition cplx.h:78
cplx< T > & operator/=(const T)
Definition cplx.h:262
cplx< T > & operator+=(const T)
Definition cplx.h:218
cplx< T > & operator*=(const T)
Definition cplx.h:245
cplx< T > cos() const
Definition cplx.h:506
cplx< T > sinh() const
Definition cplx.h:513
bool operator!=(const cplx< T > &c) const
Definition cplx.h:190
bool operator<=(const cplx< T > &c) const
Definition cplx.h:195
T cplx_base
Definition cplx.h:67
cplx< T > exp() const
Definition cplx.h:473
friend cplx< T > dot FGD(const cplx< T > &, const cplx< T > &)
cplx< T > asin() const
Definition cplx.h:525
cplx()
Definition cplx.h:71
cplx< T > conj() const
Definition cplx.h:158
cplx< T > operator/(const cplx< T > &) const
Definition cplx.h:307
T re im
Definition cplx.h:61
cplx< T > power(const double) const
Definition cplx.h:479
cplx< T > plus(const T v) const
Definition cplx.h:127
cplx< T > atanh() const
Definition cplx.h:560
T theta() const
Definition cplx.h:427
T imag() const
Definition cplx.h:107
cplx(const cplx< U > &c)
Definition cplx.h:79
T real() const
Definition cplx.h:106
cplx< T > acosh() const
Definition cplx.h:546
T abs() const
Definition cplx.h:411
bool operator==(const cplx< T > &c) const
Definition cplx.h:189
cplx< T > & do_conj()
Definition cplx.h:162
cplx< T > operator-() const
Definition cplx.h:375
cplx< T > ln() const
Definition cplx.h:493
bool operator>(const cplx< T > &c) const
Definition cplx.h:192
cplx< T > cosh() const
Definition cplx.h:519
cplx< T > operator+(const cplx< T > &) const
Definition cplx.h:280
cplx< T > div(const T a) const
Definition cplx.h:137
double norm() const
Definition cplx.h:166
T & real()
Definition cplx.h:109
T aligned_value_type TALIGN(MIN_ALIGN)
Definition cplx.h:66
bool operator<(const cplx< T > &c) const
Definition cplx.h:194
cplx< T > asinh() const
Definition cplx.h:539
T & imag()
Definition cplx.h:110
cplx< T > & operator=(const T r)
Definition cplx.h:89
T value_type
Definition cplx.h:65
cplx(const cplx< T > &c)
Definition cplx.h:73
cplx(const T r, const T i=(T) 0)
Definition cplx.h:72
cplx< T > cplx_t
Definition cplx.h:68
cplx< T > minus(const T v) const
Definition cplx.h:130
cplx< T > acos() const
Definition cplx.h:532
~cplx()
Definition cplx.h:85
cplx< T > operator~() const
Definition cplx.h:382
T re ALIGN(MIN_ALIGN)
cplx< T > mult(const T v) const
Definition cplx.h:133
bool operator>=(const cplx< T > &c) const
Definition cplx.h:193
double fabssqr() const
Definition cplx.h:164
cplx< T > sqrt() const
Definition cplx.h:467
double fabs() const
Definition cplx.h:395
cplx< T > operator*(const cplx< T > &) const
Definition cplx.h:294
cplx< T > sin() const
Definition cplx.h:499
const double pi
Definition constants.h:38
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
cplx< T > expi(const T phi)
Definition cplx.h:460
TBCI__ cplx< T > asinh(const TBCI__ cplx< T > &z)
Definition cplx.h:811
T arg(const TBCI__ cplx< T > &c)
Definition cplx.h:690
TBCI__ cplx< T > acosh(const TBCI__ cplx< T > &z)
Definition cplx.h:821
cplx< T > dot(const cplx< T > &a, const cplx< T > &b)
Definition cplx.h:300
TBCI__ cplx< T > pow(const TBCI__ cplx< T > &z, const double n)
Definition cplx.h:761
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
cplx< T > sqr(const cplx< T > &c)
Definition cplx.h:449
cplx< T > operator*(const T a, const cplx< T > &b)
Definition cplx.h:336
NAMESPACE_END NAMESPACE_CPLX TBCI__ cplx< T > conj(const TBCI__ cplx< T > &c)
Definition cplx.h:663
double norm(const TBCI__ cplx< T > &c)
Definition cplx.h:695
TBCI__ cplx< T > log(const TBCI__ cplx< T > &z)
Definition cplx.h:771
STD__ istream & operator>>(STD__ istream &in, cplx< T > &c)
Definition cplx.h:627
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
STD__ ostream & operator<<(STD__ ostream &os, const cplx< T > &c)
Definition cplx.h:621
TBCI__ cplx< T > cos(const TBCI__ cplx< T > &z)
Definition cplx.h:786
NAMESPACE_CPLX_END NAMESPACE_TBCI TBCI__ cplx< T > polar(const T &r, const T &p)
Definition cplx.h:706
#define abs(x)
Definition f2c.h:178
return c
Definition f_matrix.h:760
F_TMatrix< T > b
Definition f_matrix.h:736
const unsigned TMatrix< T > const Matrix< T > * a
#define real
double atan2(const double, const double)
#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