2 // Compiler implementation of the D programming language
3 // Copyright (c) 1999-2006 by Digital Mars
5 // written by Walter Bright and Burton Radons
7 // License for redistribution is by either the Artistic License
8 // in artistic.txt, or the GNU General Public License in gnu.txt.
9 // See the included readme.txt for details.
11 /* NOTE: This file has been patched from the original DMD distribution to
12 work with the GDC compiler.
14 Modified by David Friedman, September 2004
16 Same as DMD complex_t.h, but use GCC's REAL_VALUE_TYPE-based real_t
17 instead of long double.
20 #ifndef DMD_COMPLEX_T_H
21 #define DMD_COMPLEX_T_H
23 /* Roll our own complex type for compilers that don't support complex
32 complex_t() { this->re
= 0; this->im
= 0; }
33 complex_t(real_t re
) { this->re
= re
; this->im
= 0; }
34 complex_t(real_t re
, real_t im
) { this->re
= re
; this->im
= im
; }
36 complex_t
operator + (complex_t y
) { complex_t r
; r
.re
= re
+ y
.re
; r
.im
= im
+ y
.im
; return r
; }
37 complex_t
operator - (complex_t y
) { complex_t r
; r
.re
= re
- y
.re
; r
.im
= im
- y
.im
; return r
; }
38 complex_t
operator - () { complex_t r
; r
.re
= -re
; r
.im
= -im
; return r
; }
39 complex_t
operator * (complex_t y
) { return complex_t(re
* y
.re
- im
* y
.im
, im
* y
.re
+ re
* y
.im
); }
41 complex_t
operator / (complex_t y
)
43 real_t abs_y_re
= y
.re
.isNegative() ? -y
.re
: y
.re
;
44 real_t abs_y_im
= y
.im
.isNegative() ? -y
.im
: y
.im
;
47 if (abs_y_re
< abs_y_im
)
50 den
= y
.im
+ r
* y
.re
;
51 return complex_t((re
* r
+ im
) / den
,
57 den
= y
.re
+ r
* y
.im
;
58 return complex_t((re
+ r
* im
) / den
,
63 operator bool () { return !re
.isZero() || !im
.isZero(); }
65 int operator == (complex_t y
) { return re
== y
.re
&& im
== y
.im
; }
66 int operator != (complex_t y
) { return re
!= y
.re
|| im
!= y
.im
; }
69 inline complex_t
operator * (real_t x
, complex_t y
) { return complex_t(x
) * y
; }
70 inline complex_t
operator * (complex_t x
, real_t y
) { return x
* complex_t(y
); }
71 inline complex_t
operator / (complex_t x
, real_t y
) { return x
/ complex_t(y
); }
74 inline real_t
creall(complex_t x
)
79 inline real_t
cimagl(complex_t x
)