NumCpp  2.16.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#include <utility>
32
35
36namespace nc
37{
38 //============================================================================
39 // Method Description:
46 template<typename T>
47 bool operator<(const std::complex<T>& lhs, const std::complex<T>& rhs) noexcept
48 {
49 if (!utils::essentiallyEqual(lhs.real(), rhs.real()))
50 {
51 return lhs.real() < rhs.real();
52 }
53
54 return lhs.imag() < rhs.imag();
55 }
56
57 //============================================================================
58 // Method Description:
65 template<typename T>
66 bool operator<=(const std::complex<T>& lhs, const std::complex<T>& rhs) noexcept
67 {
68 if (!utils::essentiallyEqual(lhs.real(), rhs.real()))
69 {
70 return lhs.real() <= rhs.real();
71 }
72
73 return lhs.imag() <= rhs.imag();
74 }
75
76 //============================================================================
77 // Method Description:
84 template<typename T>
85 bool operator>(const std::complex<T>& lhs, const std::complex<T>& rhs) noexcept
86 {
87 return !(lhs <= rhs);
88 }
89
90 //============================================================================
91 // Method Description:
98 template<typename T>
99 bool operator>=(const std::complex<T>& lhs, const std::complex<T>& rhs) noexcept
100 {
101 return !(lhs < rhs);
102 }
103
104 //============================================================================
105 // Method Description:
111 template<typename Out, typename In>
112 std::complex<Out> complex_cast(const std::complex<In>& value) noexcept
113 {
115
116 return std::complex<Out>(static_cast<Out>(value.real()), static_cast<Out>(value.imag()));
117 }
118
119 //============================================================================
120 // Class Description:
123 template<typename dtype>
125 {
126 std::size_t operator()(const std::complex<dtype>& val) const
127 {
128 return std::hash<dtype>()(val.real()) ^ (std::hash<dtype>()(val.imag()) << 1);
129 }
130 };
131} // namespace nc
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition StaticAsserts.hpp:39
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition essentiallyEqual.hpp:49
Definition Cartesian.hpp:40
bool operator>=(const std::complex< T > &lhs, const std::complex< T > &rhs) noexcept
Definition StdComplexOperators.hpp:99
bool operator>(const std::complex< T > &lhs, const std::complex< T > &rhs) noexcept
Definition StdComplexOperators.hpp:85
bool operator<(const std::complex< T > &lhs, const std::complex< T > &rhs) noexcept
Definition StdComplexOperators.hpp:47
std::complex< Out > complex_cast(const std::complex< In > &value) noexcept
Definition StdComplexOperators.hpp:112
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition arange.hpp:59
bool operator<=(const std::complex< T > &lhs, const std::complex< T > &rhs) noexcept
Definition StdComplexOperators.hpp:66
Definition StdComplexOperators.hpp:125
std::size_t operator()(const std::complex< dtype > &val) const
Definition StdComplexOperators.hpp:126