@@ -19,14 +19,7 @@ import std.traits;
19
19
20
20
21
21
22
- /* * A complex number parametrised by a type T.
23
-
24
- Bugs:
25
- Some operators, such as opAssign and opOpAssign, should return by ref,
26
- but currently don't. This will be implemented as soon as
27
- $(LINK2 http://d.puremagic.com/issues/show_bug.cgi?id=2460, DMD bug 2460)
28
- is fixed.
29
- */
22
+ /* * A complex number parametrised by a type T. */
30
23
struct Complex (T) if (isFloatingPoint! T)
31
24
{
32
25
/* * The real part of the number. */
@@ -38,7 +31,7 @@ struct Complex(T) if (isFloatingPoint!T)
38
31
39
32
@safe pure nothrow // The following functions depend only on std.math.
40
33
{
41
-
34
+
42
35
/* * Calculate the absolute value (or modulus) of the number. */
43
36
@property T abs() const
44
37
{
@@ -68,7 +61,7 @@ struct Complex(T) if (isFloatingPoint!T)
68
61
69
62
70
63
// this = complex
71
- Complex opAssign (R : T)(Complex! R z)
64
+ ref Complex opAssign (R : T)(Complex! R z)
72
65
{
73
66
re = z.re;
74
67
im = z.im;
@@ -77,7 +70,7 @@ struct Complex(T) if (isFloatingPoint!T)
77
70
78
71
79
72
// this = numeric
80
- Complex opAssign (R : T)(R r)
73
+ ref Complex opAssign (R : T)(R r)
81
74
{
82
75
re = r;
83
76
im = 0 ;
@@ -196,7 +189,7 @@ struct Complex(T) if (isFloatingPoint!T)
196
189
197
190
198
191
// complex += complex, complex -= complex
199
- Complex opOpAssign (string op, C)(C z)
192
+ ref Complex opOpAssign (string op, C)(C z)
200
193
if ((op == " +" || op == " -" ) && is (C R == Complex! R))
201
194
{
202
195
mixin (" re " ~ op~ " = z.re;" );
@@ -206,7 +199,7 @@ struct Complex(T) if (isFloatingPoint!T)
206
199
207
200
208
201
// complex *= complex
209
- Complex opOpAssign (string op, C)(C z)
202
+ ref Complex opOpAssign (string op, C)(C z)
210
203
if (op == " *" && is (C R == Complex! R))
211
204
{
212
205
auto temp = re* z.re - im* z.im;
@@ -217,7 +210,7 @@ struct Complex(T) if (isFloatingPoint!T)
217
210
218
211
219
212
// complex /= complex
220
- Complex opOpAssign (string op, C)(C z)
213
+ ref Complex opOpAssign (string op, C)(C z)
221
214
if (op == " /" && is (C R == Complex! R))
222
215
{
223
216
if (fabs(z.re) < fabs(z.im))
@@ -243,7 +236,7 @@ struct Complex(T) if (isFloatingPoint!T)
243
236
244
237
245
238
// complex ^^= complex
246
- Complex opOpAssign (string op, C)(C z)
239
+ ref Complex opOpAssign (string op, C)(C z)
247
240
if (op == " ^^" && is (C R == Complex! R))
248
241
{
249
242
FPTemporary! T r = abs;
@@ -258,7 +251,7 @@ struct Complex(T) if (isFloatingPoint!T)
258
251
259
252
260
253
// complex += numeric, complex -= numeric
261
- Complex opOpAssign (string op, U : T)(U a)
254
+ ref Complex opOpAssign (string op, U : T)(U a)
262
255
if (op == " +" || op == " -" )
263
256
{
264
257
mixin (" re " ~ op~ " = a;" );
@@ -267,7 +260,7 @@ struct Complex(T) if (isFloatingPoint!T)
267
260
268
261
269
262
// complex *= numeric, complex /= numeric
270
- Complex opOpAssign (string op, U : T)(U a)
263
+ ref Complex opOpAssign (string op, U : T)(U a)
271
264
if (op == " *" || op == " /" )
272
265
{
273
266
mixin (" re " ~ op~ " = a;" );
@@ -277,7 +270,7 @@ struct Complex(T) if (isFloatingPoint!T)
277
270
278
271
279
272
// complex ^^= real
280
- Complex opOpAssign (string op, R)(R r)
273
+ ref Complex opOpAssign (string op, R)(R r)
281
274
if (op == " ^^" && isFloatingPoint! R)
282
275
{
283
276
FPTemporary! T ab = abs^^ r;
@@ -289,7 +282,7 @@ struct Complex(T) if (isFloatingPoint!T)
289
282
290
283
291
284
// complex ^^= int
292
- Complex opOpAssign (string op, U)(U i)
285
+ ref Complex opOpAssign (string op, U)(U i)
293
286
if (op == " ^^" && isIntegral! U)
294
287
{
295
288
switch (i)
0 commit comments