]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/d/dmd/complex_t.h
2 /* Compiler implementation of the D programming language
3 * Copyright (C) 1999-2021 by The D Language Foundation, All Rights Reserved
4 * written by Walter Bright
5 * http://www.digitalmars.com
6 * Distributed under the Boost Software License, Version 1.0.
7 * http://www.boost.org/LICENSE_1_0.txt
8 * https://github.com/dlang/dmd/blob/master/src/dmd/complex_t.h
13 #include "root/ctfloat.h"
15 /* Roll our own complex type for compilers that don't support complex
23 complex_t(real_t re
) : re(re
), im(ldouble(0)) {}
24 complex_t(real_t re
, real_t im
) : re(re
), im(im
) {}
26 complex_t
operator + (complex_t y
) { return complex_t(re
+ y
.re
, im
+ y
.im
); }
27 complex_t
operator - (complex_t y
) { return complex_t(re
- y
.re
, im
- y
.im
); }
28 complex_t
operator - () { return complex_t(-re
, -im
); }
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 if (CTFloat::fabs(y
.re
) < CTFloat::fabs(y
.im
))
35 real_t r
= y
.re
/ y
.im
;
36 real_t den
= y
.im
+ r
* y
.re
;
37 return complex_t((re
* r
+ im
) / den
,
42 real_t r
= y
.im
/ y
.re
;
43 real_t den
= y
.re
+ r
* y
.im
;
44 return complex_t((re
+ r
* im
) / den
,
49 operator bool () { return re
|| im
; }
51 int operator == (complex_t y
) { return re
== y
.re
&& im
== y
.im
; }
52 int operator != (complex_t y
) { return re
!= y
.re
|| im
!= y
.im
; }
55 complex_t() : re(ldouble(0)), im(ldouble(0)) {}
58 inline complex_t
operator * (real_t x
, complex_t y
) { return complex_t(x
) * y
; }
59 inline complex_t
operator * (complex_t x
, real_t y
) { return x
* complex_t(y
); }
60 inline complex_t
operator / (complex_t x
, real_t y
) { return x
/ complex_t(y
); }
63 inline real_t
creall(complex_t x
)
68 inline real_t
cimagl(complex_t x
)