tmp/tmp6m9pr9x1/{from.md → to.md}
RENAMED
|
@@ -9,19 +9,19 @@ 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
|
| 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
|
| 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
|
|
@@ -34,11 +34,11 @@ 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 |
|
|
@@ -75,11 +75,11 @@ namespace std {
|
|
| 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>&);
|
|
@@ -87,11 +87,11 @@ namespace std {
|
|
| 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>&);
|
| 96 |
|
| 97 |
template<class T> complex<T> acosh(const complex<T>&);
|
|
@@ -112,11 +112,11 @@ namespace std {
|
|
| 112 |
template<class T> complex<T> sinh (const complex<T>&);
|
| 113 |
template<class T> complex<T> sqrt (const complex<T>&);
|
| 114 |
template<class T> complex<T> tan (const complex<T>&);
|
| 115 |
template<class T> complex<T> tanh (const complex<T>&);
|
| 116 |
|
| 117 |
-
// [complex.literals], complex literals
|
| 118 |
inline namespace literals {
|
| 119 |
inline namespace complex_literals {
|
| 120 |
constexpr complex<long double> operator""il(long double);
|
| 121 |
constexpr complex<long double> operator""il(unsigned long long);
|
| 122 |
constexpr complex<double> operator""i(long double);
|
|
@@ -133,11 +133,11 @@ namespace std {
|
|
| 133 |
``` cpp
|
| 134 |
namespace std {
|
| 135 |
template<class T>
|
| 136 |
class complex {
|
| 137 |
public:
|
| 138 |
-
|
| 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 |
|
|
@@ -169,11 +169,11 @@ components, `real()` and `imag()`, of a complex number.
|
|
| 169 |
|
| 170 |
``` cpp
|
| 171 |
namespace std {
|
| 172 |
template<> class complex<float> {
|
| 173 |
public:
|
| 174 |
-
|
| 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 |
|
|
@@ -196,11 +196,11 @@ namespace std {
|
|
| 196 |
template<class X> complex<float>& operator/=(const complex<X>&);
|
| 197 |
};
|
| 198 |
|
| 199 |
template<> class complex<double> {
|
| 200 |
public:
|
| 201 |
-
|
| 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 |
|
|
@@ -223,11 +223,11 @@ namespace std {
|
|
| 223 |
template<class X> complex<double>& operator/=(const complex<X>&);
|
| 224 |
};
|
| 225 |
|
| 226 |
template<> class complex<long double> {
|
| 227 |
public:
|
| 228 |
-
|
| 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 |
|
|
@@ -258,11 +258,11 @@ namespace std {
|
|
| 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 |
-
`real() == re && imag() == im`.
|
| 264 |
|
| 265 |
``` cpp
|
| 266 |
constexpr T real() const;
|
| 267 |
```
|
| 268 |
|
|
@@ -366,73 +366,67 @@ template<class X> complex<T>& operator/=(const complex<X>& rhs);
|
|
| 366 |
|
| 367 |
``` cpp
|
| 368 |
template<class T> complex<T> operator+(const complex<T>& lhs);
|
| 369 |
```
|
| 370 |
|
| 371 |
-
*Remarks:* unary operator.
|
| 372 |
-
|
| 373 |
*Returns:* `complex<T>(lhs)`.
|
| 374 |
|
|
|
|
|
|
|
| 375 |
``` cpp
|
| 376 |
-
template<class T>
|
| 377 |
-
complex<T> operator+(const complex<T>& lhs, const complex<T>& rhs);
|
| 378 |
template<class T> complex<T> operator+(const complex<T>& lhs, const T& rhs);
|
| 379 |
template<class T> complex<T> operator+(const T& lhs, const complex<T>& rhs);
|
| 380 |
```
|
| 381 |
|
| 382 |
*Returns:* `complex<T>(lhs) += rhs`.
|
| 383 |
|
| 384 |
``` cpp
|
| 385 |
template<class T> complex<T> operator-(const complex<T>& lhs);
|
| 386 |
```
|
| 387 |
|
| 388 |
-
*Remarks:* unary operator.
|
| 389 |
-
|
| 390 |
*Returns:* `complex<T>(-lhs.real(),-lhs.imag())`.
|
| 391 |
|
|
|
|
|
|
|
| 392 |
``` cpp
|
| 393 |
-
template<class T>
|
| 394 |
-
complex<T> operator-(const complex<T>& lhs, const complex<T>& rhs);
|
| 395 |
template<class T> complex<T> operator-(const complex<T>& lhs, const T& rhs);
|
| 396 |
template<class T> complex<T> operator-(const T& lhs, const complex<T>& rhs);
|
| 397 |
```
|
| 398 |
|
| 399 |
*Returns:* `complex<T>(lhs) -= rhs`.
|
| 400 |
|
| 401 |
``` cpp
|
| 402 |
-
template<class T>
|
| 403 |
-
complex<T> operator*(const complex<T>& lhs, const complex<T>& rhs);
|
| 404 |
template<class T> complex<T> operator*(const complex<T>& lhs, const T& rhs);
|
| 405 |
template<class T> complex<T> operator*(const T& lhs, const complex<T>& rhs);
|
| 406 |
```
|
| 407 |
|
| 408 |
*Returns:* `complex<T>(lhs) *= rhs`.
|
| 409 |
|
| 410 |
``` cpp
|
| 411 |
-
template<class T>
|
| 412 |
-
complex<T> operator/(const complex<T>& lhs, const complex<T>& rhs);
|
| 413 |
template<class T> complex<T> operator/(const complex<T>& lhs, const T& rhs);
|
| 414 |
template<class T> complex<T> operator/(const T& lhs, const complex<T>& rhs);
|
| 415 |
```
|
| 416 |
|
| 417 |
*Returns:* `complex<T>(lhs) /= rhs`.
|
| 418 |
|
| 419 |
``` cpp
|
| 420 |
-
template<class T>
|
| 421 |
-
constexpr bool operator==(const complex<T>& lhs, const complex<T>& rhs);
|
| 422 |
template<class T> constexpr bool operator==(const complex<T>& lhs, const T& rhs);
|
| 423 |
template<class T> constexpr bool operator==(const T& lhs, const complex<T>& rhs);
|
| 424 |
```
|
| 425 |
|
| 426 |
*Returns:* `lhs.real() == rhs.real() && lhs.imag() == rhs.imag()`.
|
| 427 |
|
| 428 |
*Remarks:* The imaginary part is assumed to be `T()`, or 0.0, for the
|
| 429 |
`T` arguments.
|
| 430 |
|
| 431 |
``` cpp
|
| 432 |
-
template<class T>
|
| 433 |
-
constexpr bool operator!=(const complex<T>& lhs, const complex<T>& rhs);
|
| 434 |
template<class T> constexpr bool operator!=(const complex<T>& lhs, const T& rhs);
|
| 435 |
template<class T> constexpr bool operator!=(const T& lhs, const complex<T>& rhs);
|
| 436 |
```
|
| 437 |
|
| 438 |
*Returns:* `rhs.real() != lhs.real() || rhs.imag() != lhs.imag()`.
|
|
@@ -441,16 +435,16 @@ template<class T> constexpr bool operator!=(const T& lhs, const complex<T>& rhs)
|
|
| 441 |
template<class T, class charT, class traits>
|
| 442 |
basic_istream<charT, traits>&
|
| 443 |
operator>>(basic_istream<charT, traits>& is, complex<T>& x);
|
| 444 |
```
|
| 445 |
|
|
|
|
|
|
|
| 446 |
*Effects:* Extracts a complex number `x` of the form: `u`, `(u)`, or
|
| 447 |
`(u,v)`, where `u` is the real part and `v` is the imaginary
|
| 448 |
part ([[istream.formatted]]).
|
| 449 |
|
| 450 |
-
*Requires:* The input values shall be convertible to `T`.
|
| 451 |
-
|
| 452 |
If bad input is encountered, calls `is.setstate(ios_base::failbit)`
|
| 453 |
(which may throw `ios::failure` ([[iostate.flags]])).
|
| 454 |
|
| 455 |
*Returns:* `is`.
|
| 456 |
|
|
@@ -462,31 +456,27 @@ the same for each of the simpler extractions.
|
|
| 462 |
template<class T, class charT, class traits>
|
| 463 |
basic_ostream<charT, traits>&
|
| 464 |
operator<<(basic_ostream<charT, traits>& o, const complex<T>& x);
|
| 465 |
```
|
| 466 |
|
| 467 |
-
*Effects:*
|
| 468 |
were implemented as follows:
|
| 469 |
|
| 470 |
``` cpp
|
| 471 |
-
template<class T, class charT, class traits>
|
| 472 |
-
basic_ostream<charT, traits>&
|
| 473 |
-
operator<<(basic_ostream<charT, traits>& o, const complex<T>& x) {
|
| 474 |
basic_ostringstream<charT, traits> s;
|
| 475 |
s.flags(o.flags());
|
| 476 |
s.imbue(o.getloc());
|
| 477 |
s.precision(o.precision());
|
| 478 |
s << '(' << x.real() << "," << x.imag() << ')';
|
| 479 |
return o << s.str();
|
| 480 |
-
}
|
| 481 |
```
|
| 482 |
|
| 483 |
-
*Note
|
| 484 |
-
the use of comma as a field separator can be ambiguous.
|
| 485 |
-
`
|
| 486 |
-
explicit decimal point character; as a result, all inserted sequences
|
| 487 |
-
complex numbers can be extracted unambiguously.
|
| 488 |
|
| 489 |
### `complex` value operations <a id="complex.value.ops">[[complex.value.ops]]</a>
|
| 490 |
|
| 491 |
``` cpp
|
| 492 |
template<class T> constexpr T real(const complex<T>& x);
|
|
@@ -535,10 +525,13 @@ template<class T> complex<T> proj(const complex<T>& x);
|
|
| 535 |
|
| 536 |
``` cpp
|
| 537 |
template<class T> complex<T> polar(const T& rho, const T& theta = 0);
|
| 538 |
```
|
| 539 |
|
|
|
|
|
|
|
|
|
|
| 540 |
*Returns:* The `complex` value corresponding to a complex number whose
|
| 541 |
magnitude is `rho` and whose phase angle is `theta`.
|
| 542 |
|
| 543 |
### `complex` transcendentals <a id="complex.transcendentals">[[complex.transcendentals]]</a>
|
| 544 |
|
|
@@ -604,44 +597,42 @@ template<class T> complex<T> cosh(const complex<T>& x);
|
|
| 604 |
|
| 605 |
``` cpp
|
| 606 |
template<class T> complex<T> exp(const complex<T>& x);
|
| 607 |
```
|
| 608 |
|
| 609 |
-
*Returns:* The complex base
|
| 610 |
|
| 611 |
``` cpp
|
| 612 |
template<class T> complex<T> log(const complex<T>& x);
|
| 613 |
```
|
| 614 |
|
| 615 |
-
*
|
|
|
|
|
|
|
| 616 |
|
| 617 |
-
*
|
| 618 |
-
of a strip mathematically unbounded along the real axis and in the
|
| 619 |
-
interval \[`-i times pi`, `i times pi`\] along the imaginary axis. When
|
| 620 |
-
`x` is a negative real number, `imag(log(x))` is pi.
|
| 621 |
|
| 622 |
``` cpp
|
| 623 |
template<class T> complex<T> log10(const complex<T>& x);
|
| 624 |
```
|
| 625 |
|
| 626 |
-
*
|
| 627 |
-
|
| 628 |
-
*Returns:* The complex common (base 10) logarithm of `x`, defined as
|
| 629 |
`log(x) / log(10)`.
|
| 630 |
|
|
|
|
|
|
|
| 631 |
``` cpp
|
| 632 |
-
template<class T>
|
| 633 |
-
complex<T> pow(const complex<T>& x, const complex<T>& y);
|
| 634 |
template<class T> complex<T> pow(const complex<T>& x, const T& y);
|
| 635 |
template<class T> complex<T> pow(const T& x, const complex<T>& y);
|
| 636 |
```
|
| 637 |
|
| 638 |
-
*
|
| 639 |
-
|
| 640 |
-
*Returns:* The complex power of base `x` raised to the `y`-th power,
|
| 641 |
defined as `exp(y * log(x))`. The value returned for `pow(0, 0)` is
|
| 642 |
-
implementation-defined.
|
|
|
|
|
|
|
| 643 |
|
| 644 |
``` cpp
|
| 645 |
template<class T> complex<T> sin(const complex<T>& x);
|
| 646 |
```
|
| 647 |
|
|
@@ -655,16 +646,16 @@ template<class T> complex<T> sinh (const complex<T>& x);
|
|
| 655 |
|
| 656 |
``` cpp
|
| 657 |
template<class T> complex<T> sqrt(const complex<T>& x);
|
| 658 |
```
|
| 659 |
|
| 660 |
-
*Remarks:* the branch cuts are along the negative real axis.
|
| 661 |
-
|
| 662 |
*Returns:* The complex square root of `x`, in the range of the right
|
| 663 |
half-plane. If the argument is a negative real number, the value
|
| 664 |
returned lies on the positive imaginary axis.
|
| 665 |
|
|
|
|
|
|
|
| 666 |
``` cpp
|
| 667 |
template<class T> complex<T> tan(const complex<T>& x);
|
| 668 |
```
|
| 669 |
|
| 670 |
*Returns:* The complex tangent of `x`.
|
|
@@ -733,9 +724,5 @@ constexpr complex<float> operator""if(long double d);
|
|
| 733 |
constexpr complex<float> operator""if(unsigned long long d);
|
| 734 |
```
|
| 735 |
|
| 736 |
*Returns:* `complex<float>{0.0f, static_cast<float>(d)}`.
|
| 737 |
|
| 738 |
-
### Header `<ccomplex>` <a id="ccmplx">[[ccmplx]]</a>
|
| 739 |
-
|
| 740 |
-
The header behaves as if it simply includes the header `<complex>`.
|
| 741 |
-
|
|
|
|
| 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
|
|
|
|
| 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 |
|
|
|
|
| 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>&);
|
|
|
|
| 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>&);
|
| 96 |
|
| 97 |
template<class T> complex<T> acosh(const complex<T>&);
|
|
|
|
| 112 |
template<class T> complex<T> sinh (const complex<T>&);
|
| 113 |
template<class T> complex<T> sqrt (const complex<T>&);
|
| 114 |
template<class T> complex<T> tan (const complex<T>&);
|
| 115 |
template<class T> complex<T> tanh (const complex<T>&);
|
| 116 |
|
| 117 |
+
// [complex.literals], complex literals
|
| 118 |
inline namespace literals {
|
| 119 |
inline namespace complex_literals {
|
| 120 |
constexpr complex<long double> operator""il(long double);
|
| 121 |
constexpr complex<long double> operator""il(unsigned long long);
|
| 122 |
constexpr complex<double> operator""i(long double);
|
|
|
|
| 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 |
|
|
|
|
| 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 |
|
|
|
|
| 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 |
|
|
|
|
| 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 |
|
|
|
|
| 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 |
|
|
|
|
| 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()`.
|
|
|
|
| 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 |
|
|
|
|
| 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 |
|
| 464 |
``` cpp
|
|
|
|
|
|
|
|
|
|
| 465 |
basic_ostringstream<charT, traits> s;
|
| 466 |
s.flags(o.flags());
|
| 467 |
s.imbue(o.getloc());
|
| 468 |
s.precision(o.precision());
|
| 469 |
s << '(' << x.real() << "," << x.imag() << ')';
|
| 470 |
return o << s.str();
|
|
|
|
| 471 |
```
|
| 472 |
|
| 473 |
+
[*Note 1*: In a locale in which comma is used as a decimal point
|
| 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);
|
|
|
|
| 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 |
|
|
|
|
| 597 |
|
| 598 |
``` cpp
|
| 599 |
template<class T> complex<T> exp(const complex<T>& x);
|
| 600 |
```
|
| 601 |
|
| 602 |
+
*Returns:* The complex base-e exponential of `x`.
|
| 603 |
|
| 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);
|
| 616 |
```
|
| 617 |
|
| 618 |
+
*Returns:* The complex common (base-10) logarithm of `x`, defined as
|
|
|
|
|
|
|
| 619 |
`log(x) / log(10)`.
|
| 620 |
|
| 621 |
+
*Remarks:* The branch cuts are along the negative real axis.
|
| 622 |
+
|
| 623 |
``` cpp
|
| 624 |
+
template<class T> complex<T> pow(const complex<T>& x, const complex<T>& y);
|
|
|
|
| 625 |
template<class T> complex<T> pow(const complex<T>& x, const T& y);
|
| 626 |
template<class T> complex<T> pow(const T& x, const complex<T>& y);
|
| 627 |
```
|
| 628 |
|
| 629 |
+
*Returns:* The complex power of base `x` raised to the `y`ᵗʰ power,
|
|
|
|
|
|
|
| 630 |
defined as `exp(y * log(x))`. The value returned for `pow(0, 0)` is
|
| 631 |
+
*implementation-defined*.
|
| 632 |
+
|
| 633 |
+
*Remarks:* The branch cuts are along the negative real axis.
|
| 634 |
|
| 635 |
``` cpp
|
| 636 |
template<class T> complex<T> sin(const complex<T>& x);
|
| 637 |
```
|
| 638 |
|
|
|
|
| 646 |
|
| 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);
|
| 659 |
```
|
| 660 |
|
| 661 |
*Returns:* The complex tangent of `x`.
|
|
|
|
| 724 |
constexpr complex<float> operator""if(unsigned long long d);
|
| 725 |
```
|
| 726 |
|
| 727 |
*Returns:* `complex<float>{0.0f, static_cast<float>(d)}`.
|
| 728 |
|
|
|
|
|
|
|
|
|
|
|
|