USRP Hardware Driver and USRP Manual Version: 4.7.0.0-0-unknown
UHD and USRP Manual
 
Loading...
Searching...
No Matches
fp_compare_epsilon.ipp
Go to the documentation of this file.
1//
2// Copyright 2014 Ettus Research LLC
3// Copyright 2018 Ettus Research, a National Instruments Company
4//
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
7
8
9#include <cmath>
10#include <typeinfo>
11
12
13#pragma once
14
15
16namespace uhd { namespace math { namespace fp_compare {
17
18template <>
20{
21 _value = value;
22 _epsilon = SINGLE_PRECISION_EPSILON;
23}
24
25template <>
27{
28 _value = value;
29 _epsilon = DOUBLE_PRECISION_EPSILON;
30}
31
32template <typename float_t>
34 : _value(value), _epsilon(epsilon)
35{ /* NOP */
36}
37
38template <typename float_t>
41 : _value(copy._value), _epsilon(copy._epsilon)
42{ /* NOP */
43}
44
45template <typename float_t>
49
50template <typename float_t>
53{
54 _value = copy._value;
55 _epsilon = copy._epsilon;
56}
57
58template <typename float_t>
61{
62 // If raw bit values are equal, then they're equal. This also catches
63 // the case where both are 0.0!
64 if (lhs._value == rhs._value) {
65 return true;
66 }
67
68 // If one of them is within epsilon of zero, but the other is not, then
69 // they're also not equal.
70 if ((std::abs(lhs._value) <= lhs._epsilon && std::abs(rhs._value) > rhs._epsilon)
71 || (std::abs(lhs._value) > lhs._epsilon
72 && std::abs(rhs._value) <= rhs._epsilon)) {
73 return false;
74 }
75
76 // In all other cases, we use the "close enough with tolerance epsilon"
77 // algorithm as described in math.hpp.
78 const bool lhs_compare =
79 ((std::abs(lhs._value - rhs._value) / std::abs(lhs._value)) <= lhs._epsilon);
80 const bool rhs_compare =
81 ((std::abs(lhs._value - rhs._value) / std::abs(rhs._value)) <= rhs._epsilon);
82
83 return (lhs_compare || rhs_compare);
86template <typename float_t>
89{
90 return !(lhs == rhs);
91}
92
93template <typename float_t>
96{
97 return (lhs != rhs) && (lhs._value < rhs._value);
98}
99
100template <typename float_t>
103{
104 return !(lhs > rhs);
105}
106
107template <typename float_t>
110{
111 return (lhs != rhs) && (lhs._value > rhs._value);
112}
113
114template <typename float_t>
117{
118 return !(lhs < rhs);
119}
120
121template <typename float_t>
123{
124 return lhs == fp_compare_epsilon<float_t>(static_cast<float_t>(rhs));
125}
126
127template <typename float_t>
129{
130 return !(lhs == rhs);
131}
132
133template <typename float_t>
135{
136 return (lhs != rhs) && (lhs._value < rhs);
137}
138
139template <typename float_t>
141{
142 return !(lhs > rhs);
143}
144
145template <typename float_t>
147{
148 return (lhs != rhs) && (lhs._value > rhs);
149}
150
151template <typename float_t>
153{
154 return !(lhs < rhs);
155}
156
157template <typename float_t>
159{
160 return fp_compare_epsilon<float_t>(static_cast<float_t>(lhs)) == rhs;
161}
162
163template <typename float_t>
165{
166 return !(lhs == rhs);
167}
168
169template <typename float_t>
171{
172 return (lhs != rhs) && (lhs < rhs._value);
173}
174
175template <typename float_t>
177{
178 return !(lhs > rhs);
179}
180
181template <typename float_t>
183{
184 return (lhs != rhs) && (lhs > rhs._value);
185}
186
187template <typename float_t>
189{
190 return !(lhs < rhs);
191}
192
193}}} // namespace uhd::math::fp_compare
float_t _epsilon
Definition math.hpp:90
UHD_INLINE ~fp_compare_epsilon()
Definition fp_compare_epsilon.ipp:46
UHD_INLINE void operator=(const fp_compare_epsilon &copy)
Definition fp_compare_epsilon.ipp:51
float_t _value
Definition math.hpp:89
UHD_INLINE fp_compare_epsilon(float_t value)
#define UHD_INLINE
Definition config.h:65
UHD_INLINE bool operator!=(fp_compare_delta< float_t > lhs, fp_compare_delta< float_t > rhs)
Definition fp_compare_delta.ipp:71
UHD_INLINE bool operator<=(fp_compare_delta< float_t > lhs, fp_compare_delta< float_t > rhs)
Definition fp_compare_delta.ipp:84
UHD_INLINE bool operator==(fp_compare_delta< float_t > lhs, fp_compare_delta< float_t > rhs)
Definition fp_compare_delta.ipp:64
UHD_INLINE bool operator<(fp_compare_delta< float_t > lhs, fp_compare_delta< float_t > rhs)
Definition fp_compare_delta.ipp:77
UHD_INLINE bool operator>(fp_compare_delta< float_t > lhs, fp_compare_delta< float_t > rhs)
Definition fp_compare_delta.ipp:90
UHD_INLINE bool operator>=(fp_compare_delta< float_t > lhs, fp_compare_delta< float_t > rhs)
Definition fp_compare_delta.ipp:97
Definition build_info.hpp:12