NumCpp  2.18.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
essentiallyEqualComplex.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <cmath>
31#include <complex>
32#include <type_traits>
33
35
36namespace nc::utils
37{
38 //============================================================================
46 template<typename dtype, std::enable_if_t<std::is_integral<dtype>::value, int> = 0>
47 bool essentiallyEqual(const std::complex<dtype>& inValue1, const std::complex<dtype>& inValue2) noexcept
48 {
49 return inValue1 == inValue2;
50 }
51
52 //============================================================================
61 template<typename dtype, std::enable_if_t<std::is_floating_point<dtype>::value, int> = 0>
62 bool essentiallyEqual(const std::complex<dtype>& inValue1,
63 const std::complex<dtype>& inValue2,
64 const std::complex<dtype>& inEpsilon) noexcept
65 {
66 const auto absValue1 = std::abs(inValue1);
67 const auto absValue2 = std::abs(inValue2);
68 return std::abs(inValue1 - inValue2) <= ((absValue1 > absValue2 ? absValue2 : absValue1) * std::abs(inEpsilon));
69 }
70
71 //============================================================================
79 template<typename dtype, std::enable_if_t<std::is_floating_point<dtype>::value, int> = 0>
80 bool essentiallyEqual(const std::complex<dtype>& inValue1, const std::complex<dtype>& inValue2) noexcept
81 {
82 return essentiallyEqual(inValue1, inValue2, DtypeInfo<std::complex<dtype>>::epsilon());
83 }
84} // namespace nc::utils
Holds info about the dtype.
Definition DtypeInfo.hpp:41
Definition Utils/cube.hpp:33
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition essentiallyEqual.hpp:47