2 // Compiler implementation of the D programming language
3 // Copyright (c) 1999-2006 by Digital Mars
5 // written by Walter Bright and Burton Radons
6 // http://www.digitalmars.com
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 #ifndef DMD_COMPLEX_T_H
12 #define DMD_COMPLEX_T_H
14 /* Roll our own complex type for compilers that don't support complex
22 complex_t() { this->re
= 0; this->im
= 0; }
23 complex_t(long double re
) { this->re
= re
; this->im
= 0; }
24 complex_t(long double re
, long double im
) { this->re
= re
; this->im
= im
; }
26 complex_t
operator + (complex_t y
) { complex_t r
; r
.re
= re
+ y
.re
; r
.im
= im
+ y
.im
; return r
; }
27 complex_t
operator - (complex_t y
) { complex_t r
; r
.re
= re
- y
.re
; r
.im
= im
- y
.im
; return r
; }
28 complex_t
operator - () { complex_t r
; r
.re
= -re
; r
.im
= -im
; return r
; }
29 complex_t
operator * (complex_t y
) { return complex_t(re
* y
.re
- im
* y
.im
, im
* y
.re
+ re
* y
.im
); }
31 complex_t
operator / (complex_t y
)
33 long double abs_y_re
= y
.re
< 0 ? -y
.re
: y
.re
;
34 long double abs_y_im
= y
.im
< 0 ? -y
.im
: y
.im
;
37 if (abs_y_re
< abs_y_im
)
40 den
= y
.im
+ r
* y
.re
;
41 return complex_t((re
* r
+ im
) / den
,
47 den
= y
.re
+ r
* y
.im
;
48 return complex_t((re
+ r
* im
) / den
,
53 operator bool () { return re
|| im
; }
55 int operator == (complex_t y
) { return re
== y
.re
&& im
== y
.im
; }
56 int operator != (complex_t y
) { return re
!= y
.re
|| im
!= y
.im
; }
59 inline complex_t
operator * (long double x
, complex_t y
) { return complex_t(x
) * y
; }
60 inline complex_t
operator * (complex_t x
, long double y
) { return x
* complex_t(y
); }
61 inline complex_t
operator / (complex_t x
, long double y
) { return x
/ complex_t(y
); }
64 inline long double creall(complex_t x
)
69 inline long double cimagl(complex_t x
)