From Jason Turner

[complex.numbers]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpey9qtcdm/{from.md → to.md} +168 -181
tmp/tmpey9qtcdm/{from.md → to.md} RENAMED
@@ -4,92 +4,83 @@ The header `<complex>` defines a class template, and numerous functions
4
  for representing and manipulating complex numbers.
5
 
6
  The effect of instantiating the template `complex` for any type other
7
  than `float`, `double`, or `long double` is unspecified. The
8
  specializations `complex<float>`, `complex<double>`, and
9
- `complex<long double>` are literal types ([[basic.types]]).
10
 
11
  If the result of a function is not mathematically defined or not in the
12
  range of representable values for its type, the behavior is undefined.
13
 
14
- If `z` is an lvalue expression of type cv `complex<T>` then:
15
 
16
- - the expression `reinterpret_cast<cv T(&)[2]>(z)` shall be well-formed,
17
- - `reinterpret_cast<cv T(&)[2]>(z)[0]` shall designate the real part of
18
- `z`, and
19
- - `reinterpret_cast<cv T(&)[2]>(z)[1]` shall designate the imaginary
20
- part of `z`.
21
 
22
  Moreover, if `a` is an expression of type cv `complex<T>*` and the
23
  expression `a[i]` is well-defined for an integer expression `i`, then:
24
 
25
- - `reinterpret_cast<cv T*>(a)[2*i]` shall designate the real part of
26
- `a[i]`, and
27
- - `reinterpret_cast<cv T*>(a)[2*i + 1]` shall designate the imaginary
28
- part of `a[i]`.
29
 
30
  ### Header `<complex>` synopsis <a id="complex.syn">[[complex.syn]]</a>
31
 
32
  ``` cpp
33
  namespace std {
 
34
  template<class T> class complex;
 
 
35
  template<> class complex<float>;
36
  template<> class complex<double>;
37
  template<> class complex<long double>;
38
 
39
  // [complex.ops], operators
40
- template<class T>
41
- complex<T> operator+(const complex<T>&, const complex<T>&);
42
- template<class T> complex<T> operator+(const complex<T>&, const T&);
43
- template<class T> complex<T> operator+(const T&, const complex<T>&);
44
 
45
- template<class T> complex<T> operator-(
46
- const complex<T>&, const complex<T>&);
47
- template<class T> complex<T> operator-(const complex<T>&, const T&);
48
- template<class T> complex<T> operator-(const T&, const complex<T>&);
49
 
50
- template<class T> complex<T> operator*(
51
- const complex<T>&, const complex<T>&);
52
- template<class T> complex<T> operator*(const complex<T>&, const T&);
53
- template<class T> complex<T> operator*(const T&, const complex<T>&);
54
 
55
- template<class T> complex<T> operator/(
56
- const complex<T>&, const complex<T>&);
57
- template<class T> complex<T> operator/(const complex<T>&, const T&);
58
- template<class T> complex<T> operator/(const T&, const complex<T>&);
59
 
60
- template<class T> complex<T> operator+(const complex<T>&);
61
- template<class T> complex<T> operator-(const complex<T>&);
62
 
63
- template<class T> constexpr bool operator==(
64
- const complex<T>&, const complex<T>&);
65
  template<class T> constexpr bool operator==(const complex<T>&, const T&);
66
- template<class T> constexpr bool operator==(const T&, const complex<T>&);
67
-
68
- template<class T> constexpr bool operator!=(const complex<T>&, const complex<T>&);
69
- template<class T> constexpr bool operator!=(const complex<T>&, const T&);
70
- template<class T> constexpr bool operator!=(const T&, const complex<T>&);
71
 
72
  template<class T, class charT, class traits>
73
- basic_istream<charT, traits>&
74
- operator>>(basic_istream<charT, traits>&, complex<T>&);
75
 
76
  template<class T, class charT, class traits>
77
- basic_ostream<charT, traits>&
78
- operator<<(basic_ostream<charT, traits>&, const complex<T>&);
79
 
80
  // [complex.value.ops], values
81
  template<class T> constexpr T real(const complex<T>&);
82
  template<class T> constexpr T imag(const complex<T>&);
83
 
84
  template<class T> T abs(const complex<T>&);
85
  template<class T> T arg(const complex<T>&);
86
- template<class T> T norm(const complex<T>&);
87
 
88
- template<class T> complex<T> conj(const complex<T>&);
89
  template<class T> complex<T> proj(const complex<T>&);
90
- template<class T> complex<T> polar(const T&, const T& = 0);
91
 
92
  // [complex.transcendentals], transcendentals
93
  template<class T> complex<T> acos(const complex<T>&);
94
  template<class T> complex<T> asin(const complex<T>&);
95
  template<class T> complex<T> atan(const complex<T>&);
@@ -130,148 +121,148 @@ namespace std {
130
 
131
  ### Class template `complex` <a id="complex">[[complex]]</a>
132
 
133
  ``` cpp
134
  namespace std {
135
- template<class T>
136
- class complex {
137
  public:
138
  using value_type = T;
139
 
140
  constexpr complex(const T& re = T(), const T& im = T());
141
  constexpr complex(const complex&);
142
  template<class X> constexpr complex(const complex<X>&);
143
 
144
  constexpr T real() const;
145
- void real(T);
146
  constexpr T imag() const;
147
- void imag(T);
148
 
149
- complex<T>& operator= (const T&);
150
- complex<T>& operator+=(const T&);
151
- complex<T>& operator-=(const T&);
152
- complex<T>& operator*=(const T&);
153
- complex<T>& operator/=(const T&);
154
 
155
- complex& operator=(const complex&);
156
- template<class X> complex<T>& operator= (const complex<X>&);
157
- template<class X> complex<T>& operator+=(const complex<X>&);
158
- template<class X> complex<T>& operator-=(const complex<X>&);
159
- template<class X> complex<T>& operator*=(const complex<X>&);
160
- template<class X> complex<T>& operator/=(const complex<X>&);
161
  };
162
  }
163
  ```
164
 
165
  The class `complex` describes an object that can store the Cartesian
166
  components, `real()` and `imag()`, of a complex number.
167
 
168
- ### `complex` specializations <a id="complex.special">[[complex.special]]</a>
169
 
170
  ``` cpp
171
  namespace std {
172
  template<> class complex<float> {
173
  public:
174
  using value_type = float;
175
 
176
  constexpr complex(float re = 0.0f, float im = 0.0f);
 
177
  constexpr explicit complex(const complex<double>&);
178
  constexpr explicit complex(const complex<long double>&);
179
 
180
  constexpr float real() const;
181
- void real(float);
182
  constexpr float imag() const;
183
- void imag(float);
184
 
185
- complex<float>& operator= (float);
186
- complex<float>& operator+=(float);
187
- complex<float>& operator-=(float);
188
- complex<float>& operator*=(float);
189
- complex<float>& operator/=(float);
190
 
191
- complex<float>& operator=(const complex<float>&);
192
- template<class X> complex<float>& operator= (const complex<X>&);
193
- template<class X> complex<float>& operator+=(const complex<X>&);
194
- template<class X> complex<float>& operator-=(const complex<X>&);
195
- template<class X> complex<float>& operator*=(const complex<X>&);
196
- template<class X> complex<float>& operator/=(const complex<X>&);
197
  };
198
 
199
  template<> class complex<double> {
200
  public:
201
  using value_type = double;
202
 
203
  constexpr complex(double re = 0.0, double im = 0.0);
204
  constexpr complex(const complex<float>&);
 
205
  constexpr explicit complex(const complex<long double>&);
206
 
207
  constexpr double real() const;
208
- void real(double);
209
  constexpr double imag() const;
210
- void imag(double);
211
 
212
- complex<double>& operator= (double);
213
- complex<double>& operator+=(double);
214
- complex<double>& operator-=(double);
215
- complex<double>& operator*=(double);
216
- complex<double>& operator/=(double);
217
 
218
- complex<double>& operator=(const complex<double>&);
219
- template<class X> complex<double>& operator= (const complex<X>&);
220
- template<class X> complex<double>& operator+=(const complex<X>&);
221
- template<class X> complex<double>& operator-=(const complex<X>&);
222
- template<class X> complex<double>& operator*=(const complex<X>&);
223
- template<class X> complex<double>& operator/=(const complex<X>&);
224
  };
225
 
226
  template<> class complex<long double> {
227
  public:
228
  using value_type = long double;
229
 
230
  constexpr complex(long double re = 0.0L, long double im = 0.0L);
231
  constexpr complex(const complex<float>&);
232
  constexpr complex(const complex<double>&);
 
233
 
234
  constexpr long double real() const;
235
- void real(long double);
236
  constexpr long double imag() const;
237
- void imag(long double);
238
 
239
- complex<long double>& operator=(const complex<long double>&);
240
- complex<long double>& operator= (long double);
241
- complex<long double>& operator+=(long double);
242
- complex<long double>& operator-=(long double);
243
- complex<long double>& operator*=(long double);
244
- complex<long double>& operator/=(long double);
245
 
246
- template<class X> complex<long double>& operator= (const complex<X>&);
247
- template<class X> complex<long double>& operator+=(const complex<X>&);
248
- template<class X> complex<long double>& operator-=(const complex<X>&);
249
- template<class X> complex<long double>& operator*=(const complex<X>&);
250
- template<class X> complex<long double>& operator/=(const complex<X>&);
 
251
  };
252
  }
253
  ```
254
 
255
- ### `complex` member functions <a id="complex.members">[[complex.members]]</a>
256
 
257
  ``` cpp
258
  template<class T> constexpr complex(const T& re = T(), const T& im = T());
259
  ```
260
 
261
- *Effects:* Constructs an object of class `complex`.
262
-
263
- *Postconditions:* `real() == re && imag() == im`.
264
 
265
  ``` cpp
266
  constexpr T real() const;
267
  ```
268
 
269
  *Returns:* The value of the real component.
270
 
271
  ``` cpp
272
- void real(T val);
273
  ```
274
 
275
  *Effects:* Assigns `val` to the real component.
276
 
277
  ``` cpp
@@ -279,185 +270,170 @@ constexpr T imag() const;
279
  ```
280
 
281
  *Returns:* The value of the imaginary component.
282
 
283
  ``` cpp
284
- void imag(T val);
285
  ```
286
 
287
  *Effects:* Assigns `val` to the imaginary component.
288
 
289
- ### `complex` member operators <a id="complex.member.ops">[[complex.member.ops]]</a>
290
 
291
  ``` cpp
292
- complex<T>& operator+=(const T& rhs);
293
  ```
294
 
295
  *Effects:* Adds the scalar value `rhs` to the real part of the complex
296
  value `*this` and stores the result in the real part of `*this`, leaving
297
  the imaginary part unchanged.
298
 
299
  *Returns:* `*this`.
300
 
301
  ``` cpp
302
- complex<T>& operator-=(const T& rhs);
303
  ```
304
 
305
  *Effects:* Subtracts the scalar value `rhs` from the real part of the
306
  complex value `*this` and stores the result in the real part of `*this`,
307
  leaving the imaginary part unchanged.
308
 
309
  *Returns:* `*this`.
310
 
311
  ``` cpp
312
- complex<T>& operator*=(const T& rhs);
313
  ```
314
 
315
  *Effects:* Multiplies the scalar value `rhs` by the complex value
316
  `*this` and stores the result in `*this`.
317
 
318
  *Returns:* `*this`.
319
 
320
  ``` cpp
321
- complex<T>& operator/=(const T& rhs);
322
  ```
323
 
324
  *Effects:* Divides the scalar value `rhs` into the complex value `*this`
325
  and stores the result in `*this`.
326
 
327
  *Returns:* `*this`.
328
 
329
  ``` cpp
330
- template<class X> complex<T>& operator+=(const complex<X>& rhs);
331
  ```
332
 
333
  *Effects:* Adds the complex value `rhs` to the complex value `*this` and
334
  stores the sum in `*this`.
335
 
336
  *Returns:* `*this`.
337
 
338
  ``` cpp
339
- template<class X> complex<T>& operator-=(const complex<X>& rhs);
340
  ```
341
 
342
  *Effects:* Subtracts the complex value `rhs` from the complex value
343
  `*this` and stores the difference in `*this`.
344
 
345
  *Returns:* `*this`.
346
 
347
  ``` cpp
348
- template<class X> complex<T>& operator*=(const complex<X>& rhs);
349
  ```
350
 
351
  *Effects:* Multiplies the complex value `rhs` by the complex value
352
  `*this` and stores the product in `*this`.
353
 
354
  *Returns:* `*this`.
355
 
356
  ``` cpp
357
- template<class X> complex<T>& operator/=(const complex<X>& rhs);
358
  ```
359
 
360
  *Effects:* Divides the complex value `rhs` into the complex value
361
  `*this` and stores the quotient in `*this`.
362
 
363
  *Returns:* `*this`.
364
 
365
- ### `complex` non-member operations <a id="complex.ops">[[complex.ops]]</a>
366
 
367
  ``` cpp
368
- template<class T> complex<T> operator+(const complex<T>& lhs);
369
  ```
370
 
371
  *Returns:* `complex<T>(lhs)`.
372
 
373
- *Remarks:* unary operator.
374
-
375
  ``` cpp
376
- template<class T> complex<T> operator+(const complex<T>& lhs, const complex<T>& rhs);
377
- template<class T> complex<T> operator+(const complex<T>& lhs, const T& rhs);
378
- template<class T> complex<T> operator+(const T& lhs, const complex<T>& rhs);
379
  ```
380
 
381
  *Returns:* `complex<T>(lhs) += rhs`.
382
 
383
  ``` cpp
384
- template<class T> complex<T> operator-(const complex<T>& lhs);
385
  ```
386
 
387
  *Returns:* `complex<T>(-lhs.real(),-lhs.imag())`.
388
 
389
- *Remarks:* unary operator.
390
-
391
  ``` cpp
392
- template<class T> complex<T> operator-(const complex<T>& lhs, const complex<T>& rhs);
393
- template<class T> complex<T> operator-(const complex<T>& lhs, const T& rhs);
394
- template<class T> complex<T> operator-(const T& lhs, const complex<T>& rhs);
395
  ```
396
 
397
  *Returns:* `complex<T>(lhs) -= rhs`.
398
 
399
  ``` cpp
400
- template<class T> complex<T> operator*(const complex<T>& lhs, const complex<T>& rhs);
401
- template<class T> complex<T> operator*(const complex<T>& lhs, const T& rhs);
402
- template<class T> complex<T> operator*(const T& lhs, const complex<T>& rhs);
403
  ```
404
 
405
  *Returns:* `complex<T>(lhs) *= rhs`.
406
 
407
  ``` cpp
408
- template<class T> complex<T> operator/(const complex<T>& lhs, const complex<T>& rhs);
409
- template<class T> complex<T> operator/(const complex<T>& lhs, const T& rhs);
410
- template<class T> complex<T> operator/(const T& lhs, const complex<T>& rhs);
411
  ```
412
 
413
  *Returns:* `complex<T>(lhs) /= rhs`.
414
 
415
  ``` cpp
416
  template<class T> constexpr bool operator==(const complex<T>& lhs, const complex<T>& rhs);
417
  template<class T> constexpr bool operator==(const complex<T>& lhs, const T& rhs);
418
- template<class T> constexpr bool operator==(const T& lhs, const complex<T>& rhs);
419
  ```
420
 
421
  *Returns:* `lhs.real() == rhs.real() && lhs.imag() == rhs.imag()`.
422
 
423
  *Remarks:* The imaginary part is assumed to be `T()`, or 0.0, for the
424
  `T` arguments.
425
 
426
- ``` cpp
427
- template<class T> constexpr bool operator!=(const complex<T>& lhs, const complex<T>& rhs);
428
- template<class T> constexpr bool operator!=(const complex<T>& lhs, const T& rhs);
429
- template<class T> constexpr bool operator!=(const T& lhs, const complex<T>& rhs);
430
- ```
431
-
432
- *Returns:* `rhs.real() != lhs.real() || rhs.imag() != lhs.imag()`.
433
-
434
  ``` cpp
435
  template<class T, class charT, class traits>
436
- basic_istream<charT, traits>&
437
- operator>>(basic_istream<charT, traits>& is, complex<T>& x);
438
  ```
439
 
440
- *Requires:* The input values shall be convertible to `T`.
441
 
442
  *Effects:* Extracts a complex number `x` of the form: `u`, `(u)`, or
443
  `(u,v)`, where `u` is the real part and `v` is the imaginary
444
- part ([[istream.formatted]]).
445
 
446
  If bad input is encountered, calls `is.setstate(ios_base::failbit)`
447
- (which may throw `ios::failure` ([[iostate.flags]])).
448
 
449
  *Returns:* `is`.
450
 
451
  *Remarks:* This extraction is performed as a series of simpler
452
  extractions. Therefore, the skipping of whitespace is specified to be
453
  the same for each of the simpler extractions.
454
 
455
  ``` cpp
456
  template<class T, class charT, class traits>
457
- basic_ostream<charT, traits>&
458
- operator<<(basic_ostream<charT, traits>& o, const complex<T>& x);
459
  ```
460
 
461
  *Effects:* Inserts the complex number `x` onto the stream `o` as if it
462
  were implemented as follows:
463
 
@@ -474,11 +450,11 @@ return o << s.str();
474
  character, the use of comma as a field separator can be ambiguous.
475
  Inserting `showpoint` into the output stream forces all outputs to show
476
  an explicit decimal point character; as a result, all inserted sequences
477
  of complex numbers can be extracted unambiguously. — *end note*]
478
 
479
- ### `complex` value operations <a id="complex.value.ops">[[complex.value.ops]]</a>
480
 
481
  ``` cpp
482
  template<class T> constexpr T real(const complex<T>& x);
483
  ```
484
 
@@ -501,89 +477,94 @@ template<class T> T arg(const complex<T>& x);
501
  ```
502
 
503
  *Returns:* The phase angle of `x`, or `atan2(imag(x), real(x))`.
504
 
505
  ``` cpp
506
- template<class T> T norm(const complex<T>& x);
507
  ```
508
 
509
  *Returns:* The squared magnitude of `x`.
510
 
511
  ``` cpp
512
- template<class T> complex<T> conj(const complex<T>& x);
513
  ```
514
 
515
  *Returns:* The complex conjugate of `x`.
516
 
517
  ``` cpp
518
  template<class T> complex<T> proj(const complex<T>& x);
519
  ```
520
 
521
  *Returns:* The projection of `x` onto the Riemann sphere.
522
 
523
- *Remarks:* Behaves the same as the C function `cproj`, defined in
524
- 7.3.9.4.
525
 
526
  ``` cpp
527
- template<class T> complex<T> polar(const T& rho, const T& theta = 0);
528
  ```
529
 
530
- *Requires:* `rho` shall be non-negative and non-NaN. `theta` shall be
531
- finite.
532
 
533
  *Returns:* The `complex` value corresponding to a complex number whose
534
  magnitude is `rho` and whose phase angle is `theta`.
535
 
536
- ### `complex` transcendentals <a id="complex.transcendentals">[[complex.transcendentals]]</a>
537
 
538
  ``` cpp
539
  template<class T> complex<T> acos(const complex<T>& x);
540
  ```
541
 
542
  *Returns:* The complex arc cosine of `x`.
543
 
544
- *Remarks:* Behaves the same as C function `cacos`, defined in 7.3.5.1.
 
545
 
546
  ``` cpp
547
  template<class T> complex<T> asin(const complex<T>& x);
548
  ```
549
 
550
  *Returns:* The complex arc sine of `x`.
551
 
552
- *Remarks:* Behaves the same as C function `casin`, defined in 7.3.5.2.
 
553
 
554
  ``` cpp
555
  template<class T> complex<T> atan(const complex<T>& x);
556
  ```
557
 
558
  *Returns:* The complex arc tangent of `x`.
559
 
560
- *Remarks:* Behaves the same as C function `catan`, defined in 7.3.5.3.
 
561
 
562
  ``` cpp
563
  template<class T> complex<T> acosh(const complex<T>& x);
564
  ```
565
 
566
  *Returns:* The complex arc hyperbolic cosine of `x`.
567
 
568
- *Remarks:* Behaves the same as C function `cacosh`, defined in 7.3.6.1.
 
569
 
570
  ``` cpp
571
  template<class T> complex<T> asinh(const complex<T>& x);
572
  ```
573
 
574
  *Returns:* The complex arc hyperbolic sine of `x`.
575
 
576
- *Remarks:* Behaves the same as C function `casinh`, defined in 7.3.6.2.
 
577
 
578
  ``` cpp
579
  template<class T> complex<T> atanh(const complex<T>& x);
580
  ```
581
 
582
  *Returns:* The complex arc hyperbolic tangent of `x`.
583
 
584
- *Remarks:* Behaves the same as C function `catanh`, defined in 7.3.6.3.
 
585
 
586
  ``` cpp
587
  template<class T> complex<T> cos(const complex<T>& x);
588
  ```
589
 
@@ -604,12 +585,14 @@ template<class T> complex<T> exp(const complex<T>& x);
604
  ``` cpp
605
  template<class T> complex<T> log(const complex<T>& x);
606
  ```
607
 
608
  *Returns:* The complex natural (base-e) logarithm of `x`. For all `x`,
609
- `imag(log(x))` lies in the interval \[-π, π\], and when `x` is a
610
- negative real number, `imag(log(x))` is π.
 
 
611
 
612
  *Remarks:* The branch cuts are along the negative real axis.
613
 
614
  ``` cpp
615
  template<class T> complex<T> log10(const complex<T>& x);
@@ -647,12 +630,14 @@ template<class T> complex<T> sinh(const complex<T>& x);
647
  ``` cpp
648
  template<class T> complex<T> sqrt(const complex<T>& x);
649
  ```
650
 
651
  *Returns:* The complex square root of `x`, in the range of the right
652
- half-plane. If the argument is a negative real number, the value
653
- returned lies on the positive imaginary axis.
 
 
654
 
655
  *Remarks:* The branch cuts are along the negative real axis.
656
 
657
  ``` cpp
658
  template<class T> complex<T> tan(const complex<T>& x);
@@ -674,38 +659,40 @@ The following function templates shall have additional overloads:
674
  arg norm
675
  conj proj
676
  imag real
677
  ```
678
 
 
 
679
  The additional overloads shall be sufficient to ensure:
680
 
681
- 1. If the argument has type `long double`, then it is effectively cast
682
- to `complex<long double>`.
683
- 2. Otherwise, if the argument has type `double` or an integer type,
684
- then it is effectively cast to `complex<{}double>`.
685
- 3. Otherwise, if the argument has type `float`, then it is effectively
686
  cast to `complex<float>`.
687
 
688
  Function template `pow` shall have additional overloads sufficient to
689
  ensure, for a call with at least one argument of type `complex<T>`:
690
 
691
- 1. If either argument has type `complex<long double>` or type `long
692
  double`, then both arguments are effectively cast to
693
  `complex<long double>`.
694
- 2. Otherwise, if either argument has type `complex<double>`, `double`,
695
- or an integer type, then both arguments are effectively cast to
696
  `complex<double>`.
697
- 3. Otherwise, if either argument has type `complex<float>` or `float`,
698
  then both arguments are effectively cast to `complex<float>`.
699
 
700
  ### Suffixes for complex number literals <a id="complex.literals">[[complex.literals]]</a>
701
 
702
- This section describes literal suffixes for constructing complex number
703
- literals. The suffixes `i`, `il`, and `if` create complex numbers of the
704
- types `complex<double>`, `complex<long double>`, and `complex<float>`
705
- respectively, with their imaginary part denoted by the given literal
706
- number and the real part being zero.
707
 
708
  ``` cpp
709
  constexpr complex<long double> operator""il(long double d);
710
  constexpr complex<long double> operator""il(unsigned long long d);
711
  ```
 
4
  for representing and manipulating complex numbers.
5
 
6
  The effect of instantiating the template `complex` for any type other
7
  than `float`, `double`, or `long double` is unspecified. The
8
  specializations `complex<float>`, `complex<double>`, and
9
+ `complex<long double>` are literal types [[basic.types]].
10
 
11
  If the result of a function is not mathematically defined or not in the
12
  range of representable values for its type, the behavior is undefined.
13
 
14
+ If `z` is an lvalue of type cv `complex<T>` then:
15
 
16
+ - the expression `reinterpret_cast<cv T(&)[2]>(z)` is well-formed,
17
+ - `reinterpret_cast<cv T(&)[2]>(z)[0]` designates the real part of `z`,
18
+ and
19
+ - `reinterpret_cast<cv T(&)[2]>(z)[1]` designates the imaginary part of
20
+ `z`.
21
 
22
  Moreover, if `a` is an expression of type cv `complex<T>*` and the
23
  expression `a[i]` is well-defined for an integer expression `i`, then:
24
 
25
+ - `reinterpret_cast<cv T*>(a)[2*i]` designates the real part of `a[i]`,
26
+ and
27
+ - `reinterpret_cast<cv T*>(a)[2*i + 1]` designates the imaginary part of
28
+ `a[i]`.
29
 
30
  ### Header `<complex>` synopsis <a id="complex.syn">[[complex.syn]]</a>
31
 
32
  ``` cpp
33
  namespace std {
34
+ // [complex], class template complex
35
  template<class T> class complex;
36
+
37
+ // [complex.special], specializations
38
  template<> class complex<float>;
39
  template<> class complex<double>;
40
  template<> class complex<long double>;
41
 
42
  // [complex.ops], operators
43
+ template<class T> constexpr complex<T> operator+(const complex<T>&, const complex<T>&);
44
+ template<class T> constexpr complex<T> operator+(const complex<T>&, const T&);
45
+ template<class T> constexpr complex<T> operator+(const T&, const complex<T>&);
 
46
 
47
+ template<class T> constexpr complex<T> operator-(const complex<T>&, const complex<T>&);
48
+ template<class T> constexpr complex<T> operator-(const complex<T>&, const T&);
49
+ template<class T> constexpr complex<T> operator-(const T&, const complex<T>&);
 
50
 
51
+ template<class T> constexpr complex<T> operator*(const complex<T>&, const complex<T>&);
52
+ template<class T> constexpr complex<T> operator*(const complex<T>&, const T&);
53
+ template<class T> constexpr complex<T> operator*(const T&, const complex<T>&);
 
54
 
55
+ template<class T> constexpr complex<T> operator/(const complex<T>&, const complex<T>&);
56
+ template<class T> constexpr complex<T> operator/(const complex<T>&, const T&);
57
+ template<class T> constexpr complex<T> operator/(const T&, const complex<T>&);
 
58
 
59
+ template<class T> constexpr complex<T> operator+(const complex<T>&);
60
+ template<class T> constexpr complex<T> operator-(const complex<T>&);
61
 
62
+ template<class T> constexpr bool operator==(const complex<T>&, const complex<T>&);
 
63
  template<class T> constexpr bool operator==(const complex<T>&, const T&);
 
 
 
 
 
64
 
65
  template<class T, class charT, class traits>
66
+ basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>&, complex<T>&);
 
67
 
68
  template<class T, class charT, class traits>
69
+ basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>&, const complex<T>&);
 
70
 
71
  // [complex.value.ops], values
72
  template<class T> constexpr T real(const complex<T>&);
73
  template<class T> constexpr T imag(const complex<T>&);
74
 
75
  template<class T> T abs(const complex<T>&);
76
  template<class T> T arg(const complex<T>&);
77
+ template<class T> constexpr T norm(const complex<T>&);
78
 
79
+ template<class T> constexpr complex<T> conj(const complex<T>&);
80
  template<class T> complex<T> proj(const complex<T>&);
81
+ template<class T> complex<T> polar(const T&, const T& = T());
82
 
83
  // [complex.transcendentals], transcendentals
84
  template<class T> complex<T> acos(const complex<T>&);
85
  template<class T> complex<T> asin(const complex<T>&);
86
  template<class T> complex<T> atan(const complex<T>&);
 
121
 
122
  ### Class template `complex` <a id="complex">[[complex]]</a>
123
 
124
  ``` cpp
125
  namespace std {
126
+ template<class T> class complex {
 
127
  public:
128
  using value_type = T;
129
 
130
  constexpr complex(const T& re = T(), const T& im = T());
131
  constexpr complex(const complex&);
132
  template<class X> constexpr complex(const complex<X>&);
133
 
134
  constexpr T real() const;
135
+ constexpr void real(T);
136
  constexpr T imag() const;
137
+ constexpr void imag(T);
138
 
139
+ constexpr complex& operator= (const T&);
140
+ constexpr complex& operator+=(const T&);
141
+ constexpr complex& operator-=(const T&);
142
+ constexpr complex& operator*=(const T&);
143
+ constexpr complex& operator/=(const T&);
144
 
145
+ constexpr complex& operator=(const complex&);
146
+ template<class X> constexpr complex& operator= (const complex<X>&);
147
+ template<class X> constexpr complex& operator+=(const complex<X>&);
148
+ template<class X> constexpr complex& operator-=(const complex<X>&);
149
+ template<class X> constexpr complex& operator*=(const complex<X>&);
150
+ template<class X> constexpr complex& operator/=(const complex<X>&);
151
  };
152
  }
153
  ```
154
 
155
  The class `complex` describes an object that can store the Cartesian
156
  components, `real()` and `imag()`, of a complex number.
157
 
158
+ ### Specializations <a id="complex.special">[[complex.special]]</a>
159
 
160
  ``` cpp
161
  namespace std {
162
  template<> class complex<float> {
163
  public:
164
  using value_type = float;
165
 
166
  constexpr complex(float re = 0.0f, float im = 0.0f);
167
+ constexpr complex(const complex<float>&) = default;
168
  constexpr explicit complex(const complex<double>&);
169
  constexpr explicit complex(const complex<long double>&);
170
 
171
  constexpr float real() const;
172
+ constexpr void real(float);
173
  constexpr float imag() const;
174
+ constexpr void imag(float);
175
 
176
+ constexpr complex& operator= (float);
177
+ constexpr complex& operator+=(float);
178
+ constexpr complex& operator-=(float);
179
+ constexpr complex& operator*=(float);
180
+ constexpr complex& operator/=(float);
181
 
182
+ constexpr complex& operator=(const complex&);
183
+ template<class X> constexpr complex& operator= (const complex<X>&);
184
+ template<class X> constexpr complex& operator+=(const complex<X>&);
185
+ template<class X> constexpr complex& operator-=(const complex<X>&);
186
+ template<class X> constexpr complex& operator*=(const complex<X>&);
187
+ template<class X> constexpr complex& operator/=(const complex<X>&);
188
  };
189
 
190
  template<> class complex<double> {
191
  public:
192
  using value_type = double;
193
 
194
  constexpr complex(double re = 0.0, double im = 0.0);
195
  constexpr complex(const complex<float>&);
196
+ constexpr complex(const complex<double>&) = default;
197
  constexpr explicit complex(const complex<long double>&);
198
 
199
  constexpr double real() const;
200
+ constexpr void real(double);
201
  constexpr double imag() const;
202
+ constexpr void imag(double);
203
 
204
+ constexpr complex& operator= (double);
205
+ constexpr complex& operator+=(double);
206
+ constexpr complex& operator-=(double);
207
+ constexpr complex& operator*=(double);
208
+ constexpr complex& operator/=(double);
209
 
210
+ constexpr complex& operator=(const complex&);
211
+ template<class X> constexpr complex& operator= (const complex<X>&);
212
+ template<class X> constexpr complex& operator+=(const complex<X>&);
213
+ template<class X> constexpr complex& operator-=(const complex<X>&);
214
+ template<class X> constexpr complex& operator*=(const complex<X>&);
215
+ template<class X> constexpr complex& operator/=(const complex<X>&);
216
  };
217
 
218
  template<> class complex<long double> {
219
  public:
220
  using value_type = long double;
221
 
222
  constexpr complex(long double re = 0.0L, long double im = 0.0L);
223
  constexpr complex(const complex<float>&);
224
  constexpr complex(const complex<double>&);
225
+ constexpr complex(const complex<long double>&) = default;
226
 
227
  constexpr long double real() const;
228
+ constexpr void real(long double);
229
  constexpr long double imag() const;
230
+ constexpr void imag(long double);
231
 
232
+ constexpr complex& operator= (long double);
233
+ constexpr complex& operator+=(long double);
234
+ constexpr complex& operator-=(long double);
235
+ constexpr complex& operator*=(long double);
236
+ constexpr complex& operator/=(long double);
 
237
 
238
+ constexpr complex& operator=(const complex&);
239
+ template<class X> constexpr complex& operator= (const complex<X>&);
240
+ template<class X> constexpr complex& operator+=(const complex<X>&);
241
+ template<class X> constexpr complex& operator-=(const complex<X>&);
242
+ template<class X> constexpr complex& operator*=(const complex<X>&);
243
+ template<class X> constexpr complex& operator/=(const complex<X>&);
244
  };
245
  }
246
  ```
247
 
248
+ ### Member functions <a id="complex.members">[[complex.members]]</a>
249
 
250
  ``` cpp
251
  template<class T> constexpr complex(const T& re = T(), const T& im = T());
252
  ```
253
 
254
+ *Ensures:* `real() == re && imag() == im` is `true`.
 
 
255
 
256
  ``` cpp
257
  constexpr T real() const;
258
  ```
259
 
260
  *Returns:* The value of the real component.
261
 
262
  ``` cpp
263
+ constexpr void real(T val);
264
  ```
265
 
266
  *Effects:* Assigns `val` to the real component.
267
 
268
  ``` cpp
 
270
  ```
271
 
272
  *Returns:* The value of the imaginary component.
273
 
274
  ``` cpp
275
+ constexpr void imag(T val);
276
  ```
277
 
278
  *Effects:* Assigns `val` to the imaginary component.
279
 
280
+ ### Member operators <a id="complex.member.ops">[[complex.member.ops]]</a>
281
 
282
  ``` cpp
283
+ constexpr complex& operator+=(const T& rhs);
284
  ```
285
 
286
  *Effects:* Adds the scalar value `rhs` to the real part of the complex
287
  value `*this` and stores the result in the real part of `*this`, leaving
288
  the imaginary part unchanged.
289
 
290
  *Returns:* `*this`.
291
 
292
  ``` cpp
293
+ constexpr complex& operator-=(const T& rhs);
294
  ```
295
 
296
  *Effects:* Subtracts the scalar value `rhs` from the real part of the
297
  complex value `*this` and stores the result in the real part of `*this`,
298
  leaving the imaginary part unchanged.
299
 
300
  *Returns:* `*this`.
301
 
302
  ``` cpp
303
+ constexpr complex& operator*=(const T& rhs);
304
  ```
305
 
306
  *Effects:* Multiplies the scalar value `rhs` by the complex value
307
  `*this` and stores the result in `*this`.
308
 
309
  *Returns:* `*this`.
310
 
311
  ``` cpp
312
+ constexpr complex& operator/=(const T& rhs);
313
  ```
314
 
315
  *Effects:* Divides the scalar value `rhs` into the complex value `*this`
316
  and stores the result in `*this`.
317
 
318
  *Returns:* `*this`.
319
 
320
  ``` cpp
321
+ template<class X> constexpr complex& operator+=(const complex<X>& rhs);
322
  ```
323
 
324
  *Effects:* Adds the complex value `rhs` to the complex value `*this` and
325
  stores the sum in `*this`.
326
 
327
  *Returns:* `*this`.
328
 
329
  ``` cpp
330
+ template<class X> constexpr complex& operator-=(const complex<X>& rhs);
331
  ```
332
 
333
  *Effects:* Subtracts the complex value `rhs` from the complex value
334
  `*this` and stores the difference in `*this`.
335
 
336
  *Returns:* `*this`.
337
 
338
  ``` cpp
339
+ template<class X> constexpr complex& operator*=(const complex<X>& rhs);
340
  ```
341
 
342
  *Effects:* Multiplies the complex value `rhs` by the complex value
343
  `*this` and stores the product in `*this`.
344
 
345
  *Returns:* `*this`.
346
 
347
  ``` cpp
348
+ template<class X> constexpr complex& operator/=(const complex<X>& rhs);
349
  ```
350
 
351
  *Effects:* Divides the complex value `rhs` into the complex value
352
  `*this` and stores the quotient in `*this`.
353
 
354
  *Returns:* `*this`.
355
 
356
+ ### Non-member operations <a id="complex.ops">[[complex.ops]]</a>
357
 
358
  ``` cpp
359
+ template<class T> constexpr complex<T> operator+(const complex<T>& lhs);
360
  ```
361
 
362
  *Returns:* `complex<T>(lhs)`.
363
 
 
 
364
  ``` cpp
365
+ template<class T> constexpr complex<T> operator+(const complex<T>& lhs, const complex<T>& rhs);
366
+ template<class T> constexpr complex<T> operator+(const complex<T>& lhs, const T& rhs);
367
+ template<class T> constexpr complex<T> operator+(const T& lhs, const complex<T>& rhs);
368
  ```
369
 
370
  *Returns:* `complex<T>(lhs) += rhs`.
371
 
372
  ``` cpp
373
+ template<class T> constexpr complex<T> operator-(const complex<T>& lhs);
374
  ```
375
 
376
  *Returns:* `complex<T>(-lhs.real(),-lhs.imag())`.
377
 
 
 
378
  ``` cpp
379
+ template<class T> constexpr complex<T> operator-(const complex<T>& lhs, const complex<T>& rhs);
380
+ template<class T> constexpr complex<T> operator-(const complex<T>& lhs, const T& rhs);
381
+ template<class T> constexpr complex<T> operator-(const T& lhs, const complex<T>& rhs);
382
  ```
383
 
384
  *Returns:* `complex<T>(lhs) -= rhs`.
385
 
386
  ``` cpp
387
+ template<class T> constexpr complex<T> operator*(const complex<T>& lhs, const complex<T>& rhs);
388
+ template<class T> constexpr complex<T> operator*(const complex<T>& lhs, const T& rhs);
389
+ template<class T> constexpr complex<T> operator*(const T& lhs, const complex<T>& rhs);
390
  ```
391
 
392
  *Returns:* `complex<T>(lhs) *= rhs`.
393
 
394
  ``` cpp
395
+ template<class T> constexpr complex<T> operator/(const complex<T>& lhs, const complex<T>& rhs);
396
+ template<class T> constexpr complex<T> operator/(const complex<T>& lhs, const T& rhs);
397
+ template<class T> constexpr complex<T> operator/(const T& lhs, const complex<T>& rhs);
398
  ```
399
 
400
  *Returns:* `complex<T>(lhs) /= rhs`.
401
 
402
  ``` cpp
403
  template<class T> constexpr bool operator==(const complex<T>& lhs, const complex<T>& rhs);
404
  template<class T> constexpr bool operator==(const complex<T>& lhs, const T& rhs);
 
405
  ```
406
 
407
  *Returns:* `lhs.real() == rhs.real() && lhs.imag() == rhs.imag()`.
408
 
409
  *Remarks:* The imaginary part is assumed to be `T()`, or 0.0, for the
410
  `T` arguments.
411
 
 
 
 
 
 
 
 
 
412
  ``` cpp
413
  template<class T, class charT, class traits>
414
+ basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, complex<T>& x);
 
415
  ```
416
 
417
+ *Preconditions:* The input values are convertible to `T`.
418
 
419
  *Effects:* Extracts a complex number `x` of the form: `u`, `(u)`, or
420
  `(u,v)`, where `u` is the real part and `v` is the imaginary
421
+ part [[istream.formatted]].
422
 
423
  If bad input is encountered, calls `is.setstate(ios_base::failbit)`
424
+ (which may throw `ios_base::failure` [[iostate.flags]]).
425
 
426
  *Returns:* `is`.
427
 
428
  *Remarks:* This extraction is performed as a series of simpler
429
  extractions. Therefore, the skipping of whitespace is specified to be
430
  the same for each of the simpler extractions.
431
 
432
  ``` cpp
433
  template<class T, class charT, class traits>
434
+ basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& o, const complex<T>& x);
 
435
  ```
436
 
437
  *Effects:* Inserts the complex number `x` onto the stream `o` as if it
438
  were implemented as follows:
439
 
 
450
  character, the use of comma as a field separator can be ambiguous.
451
  Inserting `showpoint` into the output stream forces all outputs to show
452
  an explicit decimal point character; as a result, all inserted sequences
453
  of complex numbers can be extracted unambiguously. — *end note*]
454
 
455
+ ### Value operations <a id="complex.value.ops">[[complex.value.ops]]</a>
456
 
457
  ``` cpp
458
  template<class T> constexpr T real(const complex<T>& x);
459
  ```
460
 
 
477
  ```
478
 
479
  *Returns:* The phase angle of `x`, or `atan2(imag(x), real(x))`.
480
 
481
  ``` cpp
482
+ template<class T> constexpr T norm(const complex<T>& x);
483
  ```
484
 
485
  *Returns:* The squared magnitude of `x`.
486
 
487
  ``` cpp
488
+ template<class T> constexpr complex<T> conj(const complex<T>& x);
489
  ```
490
 
491
  *Returns:* The complex conjugate of `x`.
492
 
493
  ``` cpp
494
  template<class T> complex<T> proj(const complex<T>& x);
495
  ```
496
 
497
  *Returns:* The projection of `x` onto the Riemann sphere.
498
 
499
+ *Remarks:* Behaves the same as the C function `cproj`. See also: ISO C
500
+ 7.3.9.5
501
 
502
  ``` cpp
503
+ template<class T> complex<T> polar(const T& rho, const T& theta = T());
504
  ```
505
 
506
+ *Preconditions:* `rho` is non-negative and non-NaN. `theta` is finite.
 
507
 
508
  *Returns:* The `complex` value corresponding to a complex number whose
509
  magnitude is `rho` and whose phase angle is `theta`.
510
 
511
+ ### Transcendentals <a id="complex.transcendentals">[[complex.transcendentals]]</a>
512
 
513
  ``` cpp
514
  template<class T> complex<T> acos(const complex<T>& x);
515
  ```
516
 
517
  *Returns:* The complex arc cosine of `x`.
518
 
519
+ *Remarks:* Behaves the same as the C function `cacos`. See also: ISO C
520
+ 7.3.5.1
521
 
522
  ``` cpp
523
  template<class T> complex<T> asin(const complex<T>& x);
524
  ```
525
 
526
  *Returns:* The complex arc sine of `x`.
527
 
528
+ *Remarks:* Behaves the same as the C function `casin`. See also: ISO C
529
+ 7.3.5.2
530
 
531
  ``` cpp
532
  template<class T> complex<T> atan(const complex<T>& x);
533
  ```
534
 
535
  *Returns:* The complex arc tangent of `x`.
536
 
537
+ *Remarks:* Behaves the same as the C function `catan`. See also: ISO C
538
+ 7.3.5.3
539
 
540
  ``` cpp
541
  template<class T> complex<T> acosh(const complex<T>& x);
542
  ```
543
 
544
  *Returns:* The complex arc hyperbolic cosine of `x`.
545
 
546
+ *Remarks:* Behaves the same as the C function `cacosh`. See also: ISO C
547
+ 7.3.6.1
548
 
549
  ``` cpp
550
  template<class T> complex<T> asinh(const complex<T>& x);
551
  ```
552
 
553
  *Returns:* The complex arc hyperbolic sine of `x`.
554
 
555
+ *Remarks:* Behaves the same as the C function `casinh`. See also: ISO C
556
+ 7.3.6.2
557
 
558
  ``` cpp
559
  template<class T> complex<T> atanh(const complex<T>& x);
560
  ```
561
 
562
  *Returns:* The complex arc hyperbolic tangent of `x`.
563
 
564
+ *Remarks:* Behaves the same as the C function `catanh`. See also: ISO C
565
+ 7.3.6.3
566
 
567
  ``` cpp
568
  template<class T> complex<T> cos(const complex<T>& x);
569
  ```
570
 
 
585
  ``` cpp
586
  template<class T> complex<T> log(const complex<T>& x);
587
  ```
588
 
589
  *Returns:* The complex natural (base-e) logarithm of `x`. For all `x`,
590
+ `imag(log(x))` lies in the interval \[-π, π\].
591
+
592
+ [*Note 1*: The semantics of this function are intended to be the same
593
+ in C++ as they are for `clog` in C. — *end note*]
594
 
595
  *Remarks:* The branch cuts are along the negative real axis.
596
 
597
  ``` cpp
598
  template<class T> complex<T> log10(const complex<T>& x);
 
630
  ``` cpp
631
  template<class T> complex<T> sqrt(const complex<T>& x);
632
  ```
633
 
634
  *Returns:* The complex square root of `x`, in the range of the right
635
+ half-plane.
636
+
637
+ [*Note 2*: The semantics of this function are intended to be the same
638
+ in C++ as they are for `csqrt` in C. — *end note*]
639
 
640
  *Remarks:* The branch cuts are along the negative real axis.
641
 
642
  ``` cpp
643
  template<class T> complex<T> tan(const complex<T>& x);
 
659
  arg norm
660
  conj proj
661
  imag real
662
  ```
663
 
664
+ where `norm`, `conj`, `imag`, and `real` are `constexpr` overloads.
665
+
666
  The additional overloads shall be sufficient to ensure:
667
 
668
+ - If the argument has type `long double`, then it is effectively cast to
669
+ `complex<long double>`.
670
+ - Otherwise, if the argument has type `double` or an integer type, then
671
+ it is effectively cast to `complex<{}double>`.
672
+ - Otherwise, if the argument has type `float`, then it is effectively
673
  cast to `complex<float>`.
674
 
675
  Function template `pow` shall have additional overloads sufficient to
676
  ensure, for a call with at least one argument of type `complex<T>`:
677
 
678
+ - If either argument has type `complex<long double>` or type `long
679
  double`, then both arguments are effectively cast to
680
  `complex<long double>`.
681
+ - Otherwise, if either argument has type `complex<double>`, `double`, or
682
+ an integer type, then both arguments are effectively cast to
683
  `complex<double>`.
684
+ - Otherwise, if either argument has type `complex<float>` or `float`,
685
  then both arguments are effectively cast to `complex<float>`.
686
 
687
  ### Suffixes for complex number literals <a id="complex.literals">[[complex.literals]]</a>
688
 
689
+ This subclause describes literal suffixes for constructing complex
690
+ number literals. The suffixes `i`, `il`, and `if` create complex numbers
691
+ of the types `complex<double>`, `complex<long double>`, and
692
+ `complex<float>` respectively, with their imaginary part denoted by the
693
+ given literal number and the real part being zero.
694
 
695
  ``` cpp
696
  constexpr complex<long double> operator""il(long double d);
697
  constexpr complex<long double> operator""il(unsigned long long d);
698
  ```