NumCpp  2.18.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
StdComplexOperators.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <complex>
31
34
35namespace nc
36{
37 //============================================================================
38 // Method Description:
45 template<typename T>
46 bool operator<(const std::complex<T>& lhs, const std::complex<T>& rhs) noexcept
47 {
48 if (!utils::essentiallyEqual(lhs.real(), rhs.real()))
49 {
50 return lhs.real() < rhs.real();
51 }
52
53 return lhs.imag() < rhs.imag();
54 }
55
56 //============================================================================
57 // Method Description:
64 template<typename T>
65 bool operator<=(const std::complex<T>& lhs, const std::complex<T>& rhs) noexcept
66 {
67 if (!utils::essentiallyEqual(lhs.real(), rhs.real()))
68 {
69 return lhs.real() <= rhs.real();
70 }
71
72 return lhs.imag() <= rhs.imag();
73 }
74
75 //============================================================================
76 // Method Description:
83 template<typename T>
84 bool operator>(const std::complex<T>& lhs, const std::complex<T>& rhs) noexcept
85 {
86 return !(lhs <= rhs);
87 }
88
89 //============================================================================
90 // Method Description:
97 template<typename T>
98 bool operator>=(const std::complex<T>& lhs, const std::complex<T>& rhs) noexcept
99 {
100 return !(lhs < rhs);
101 }
102
103 //============================================================================
104 // Method Description:
110 template<typename Out, typename In>
111 std::complex<Out> complex_cast(const std::complex<In>& value) noexcept
112 {
114
115 return std::complex<Out>(static_cast<Out>(value.real()), static_cast<Out>(value.imag()));
116 }
117
118 //============================================================================
119 // Class Description:
122 template<typename dtype>
124 {
125 std::size_t operator()(const std::complex<dtype>& val) const
126 {
127 return std::hash<dtype>()(val.real()) ^ (std::hash<dtype>()(val.imag()) << 1);
128 }
129 };
130} // namespace nc
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition StaticAsserts.hpp:39
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition essentiallyEqual.hpp:47
Definition Cartesian.hpp:39
bool operator>=(const std::complex< T > &lhs, const std::complex< T > &rhs) noexcept
Definition StdComplexOperators.hpp:98
bool operator>(const std::complex< T > &lhs, const std::complex< T > &rhs) noexcept
Definition StdComplexOperators.hpp:84
bool operator<(const std::complex< T > &lhs, const std::complex< T > &rhs) noexcept
Definition StdComplexOperators.hpp:46
std::complex< Out > complex_cast(const std::complex< In > &value) noexcept
Definition StdComplexOperators.hpp:111
bool operator<=(const std::complex< T > &lhs, const std::complex< T > &rhs) noexcept
Definition StdComplexOperators.hpp:65
Definition StdComplexOperators.hpp:124
std::size_t operator()(const std::complex< dtype > &val) const
Definition StdComplexOperators.hpp:125