NumCpp  2.11.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
essentiallyEqualComplex.hpp
Go to the documentation of this file.
1 #pragma once
29 
30 #include <cmath>
31 #include <complex>
32 #include <string>
33 
37 
38 namespace nc::utils
39 {
40  //============================================================================
48  template<typename dtype, std::enable_if_t<std::is_integral<dtype>::value, int> = 0>
49  bool essentiallyEqual(const std::complex<dtype>& inValue1, const std::complex<dtype>& inValue2) noexcept
50  {
51  return inValue1 == inValue2;
52  }
53 
54  //============================================================================
63  template<typename dtype, std::enable_if_t<std::is_floating_point<dtype>::value, int> = 0>
64  bool essentiallyEqual(const std::complex<dtype>& inValue1,
65  const std::complex<dtype>& inValue2,
66  const std::complex<dtype>& inEpsilon) noexcept
67  {
68  const auto absValue1 = std::abs(inValue1);
69  const auto absValue2 = std::abs(inValue2);
70  return std::abs(inValue1 - inValue2) <= ((absValue1 > absValue2 ? absValue2 : absValue1) * std::abs(inEpsilon));
71  }
72 
73  //============================================================================
81  template<typename dtype, std::enable_if_t<std::is_floating_point<dtype>::value, int> = 0>
82  bool essentiallyEqual(const std::complex<dtype>& inValue1, const std::complex<dtype>& inValue2) noexcept
83  {
84  return essentiallyEqual(inValue1, inValue2, DtypeInfo<std::complex<dtype>>::epsilon());
85  }
86 } // 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:48
auto abs(dtype inValue) noexcept
Definition: abs.hpp:49