Spec-Zone.ru › C++

operator==,!=(std::complex)

Определено в заголовочном файле <complex>
template< class T >
bool operator==( const complex<T>& lhs, const complex<T>& rhs );
(1) (до C++14)
template< class T >
constexpr bool operator==( const complex<T>& lhs, const complex<T>& rhs );
(начиная с C++14)
template< class T >
bool operator==( const complex<T>& lhs, const T& rhs );
(2) (до C++14)
template< class T >
constexpr bool operator==( const complex<T>& lhs, const T& rhs );
(начиная с C++14)
template< class T >
bool operator==( const T& lhs, const complex<T>& rhs );
(3) (до C++14)
template< class T >
constexpr bool operator==( const T& lhs, const complex<T>& rhs );
(начиная с C++14)
(до C++20)
template< class T >
bool operator!=( const complex<T>& lhs, const complex<T>& rhs );
(4) (до C++14)
template< class T >
constexpr bool operator!=( const complex<T>& lhs, const complex<T>& rhs );
(начиная с C++14)
(до C++20)
template< class T >
bool operator!=( const complex<T>& lhs, const T& rhs );
(5) (до C++14)
template< class T >
constexpr bool operator!=( const complex<T>& lhs, const T& rhs );
(начиная с C++14)
(до C++20)
template< class T >
bool operator!=( const T& lhs, const complex<T>& rhs );
(6) (до C++14)
template< class T >
constexpr bool operator!=( const T& lhs, const complex<T>& rhs );
(начиная с C++14)
(до C++20)

Сравнивает два комплексных числа. Скалярные аргументы рассматриваются как комплексные числа, действительная часть которых равна аргументу, а мнимая часть равна нулю.

1-3) Сравнивает lhs и rhs на равенство.
4-6) Сравнивает lhs и rhs на неравенство.

Оператор != синтезируется на основе operator==.

(начиная с C++20)

Параметры

lhs, rhs - аргументы для сравнения: либо два комплексных числа, либо комплексное число и скаляр соответствующего типа (float, double, long double)

Возвращаемое значение

1-3) true, если соответствующие части lhs равны rhs, и false в противном случае.
4-6) !(lhs == rhs)

Пример

#include <complex>

int main()
{
    using std::operator""i; // or: using namespace std::complex_literals;

    static_assert(1.0i == 1.0i);
    static_assert(2.0i != 1.0i);

    constexpr std::complex z(1.0, 0.0);
    static_assert(z == 1.0);
    static_assert(1.0 == z);
    static_assert(2.0 != z);
    static_assert(z != 2.0);
}

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/numeric/complex/operator_cmp

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API