USRP Hardware Driver and USRP Manual: fp_compare_delta.ipp Source File

| USRP Hardware Driver and USRP Manual Version: 4.8.0.makepkg-0-g308126a4 UHD and USRP Manual |

Loading...
Searching...
No Matches
fp_compare_delta.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#pragma once
13
14
15 namespace uhd { namespace math { namespace fp_compare {
16
17template <typename float_t>
18 UHD_INLINE float_t fp_compare_select_delta(float_t lhs_delta, float_t rhs_delta)
19{
20 return ((lhs_delta > rhs_delta) ? lhs_delta : rhs_delta);
21}
22
23template <>
24 UHD_INLINE fp_compare_delta<float>::fp_compare_delta(float value)
25{
26 _value = value;
27 _delta = SINGLE_PRECISION_DELTA;
28}
29
30template <>
31 UHD_INLINE fp_compare_delta<double>::fp_compare_delta(double value)
32{
33 _value = value;
34 _delta = DOUBLE_PRECISION_DELTA;
35}
36
37template <typename float_t>
38 UHD_INLINE fp_compare_delta<float_t>::fp_compare_delta(float_t value, float_t delta)
39 : _value(value), _delta(delta)
40{ /* NOP */
41}
42
43template <typename float_t>
44 UHD_INLINE fp_compare_delta<float_t>::fp_compare_delta(
45 const fp_compare_delta<float_t>& copy)
46 : _value(copy._value), _delta(copy._delta)
47{ /* NOP */
48}
49
50template <typename float_t>
51 UHD_INLINE fp_compare_delta<float_t>::~fp_compare_delta()
52{ /* NOP */
53}
54
55template <typename float_t>
56 UHD_INLINE void fp_compare_delta<float_t>::operator=(
57 const fp_compare_delta<float_t>& copy)
58{
59 _value = copy._value;
60 _delta = copy._delta;
61}
62
63template <typename float_t>
64 UHD_INLINE bool operator==(fp_compare_delta<float_t> lhs, fp_compare_delta<float_t> rhs)
65{
66 float_t delta = fp_compare_select_delta(lhs._delta, rhs._delta);
67 return (std::abs(lhs._value - rhs._value) < delta);
68}
69
70template <typename float_t>
71 UHD_INLINE bool operator!=(fp_compare_delta<float_t> lhs, fp_compare_delta<float_t> rhs)
72{
73 return !(lhs == rhs);
74}
75
76template <typename float_t>
77 UHD_INLINE bool operator<(fp_compare_delta<float_t> lhs, fp_compare_delta<float_t> rhs)
78{
79 float_t delta = fp_compare_select_delta(lhs._delta, rhs._delta);
80 return ((rhs._value - lhs._value) > delta);
81}
82
83template <typename float_t>
84 UHD_INLINE bool operator<=(fp_compare_delta<float_t> lhs, fp_compare_delta<float_t> rhs)
85{
86 return !(lhs > rhs);
87}
88
89template <typename float_t>
90 UHD_INLINE bool operator>(fp_compare_delta<float_t> lhs, fp_compare_delta<float_t> rhs)
91{
92 float_t delta = fp_compare_select_delta(lhs._delta, rhs._delta);
93 return ((lhs._value - rhs._value) > delta);
94}
95
96template <typename float_t>
97 UHD_INLINE bool operator>=(fp_compare_delta<float_t> lhs, fp_compare_delta<float_t> rhs)
98{
99 return !(lhs < rhs);
100}
101
102template <typename float_t>
103 UHD_INLINE bool operator==(fp_compare_delta<float_t> lhs, double rhs)
104{
105 float_t delta =
106 float_t(fp_compare_select_delta(double(lhs._delta), DOUBLE_PRECISION_DELTA));
107 return (std::abs(lhs._value - rhs) < delta);
108}
109
110template <typename float_t>
111 UHD_INLINE bool operator!=(fp_compare_delta<float_t> lhs, double rhs)
112{
113 return !(lhs == rhs);
114}
115
116template <typename float_t>
117 UHD_INLINE bool operator<(fp_compare_delta<float_t> lhs, double rhs)
118{
119 float_t delta =
120 float_t(fp_compare_select_delta(double(lhs._delta), DOUBLE_PRECISION_DELTA));
121 return ((rhs - lhs._value) > delta);
122}
123
124template <typename float_t>
125 UHD_INLINE bool operator<=(fp_compare_delta<float_t> lhs, double rhs)
126{
127 return !(lhs > rhs);
128}
129
130template <typename float_t>
131 UHD_INLINE bool operator>(fp_compare_delta<float_t> lhs, double rhs)
132{
133 float_t delta =
134 float_t(fp_compare_select_delta(double(lhs._delta), DOUBLE_PRECISION_DELTA));
135 return ((lhs._value - rhs) > delta);
136}
137
138template <typename float_t>
139 UHD_INLINE bool operator>=(fp_compare_delta<float_t> lhs, double rhs)
140{
141 return !(lhs < rhs);
142}
143
144template <typename float_t>
145 UHD_INLINE bool operator==(double lhs, fp_compare_delta<float_t> rhs)
146{
147 float_t delta = fp_compare_select_delta(DOUBLE_PRECISION_DELTA, double(rhs._delta));
148 return (std::abs(lhs - rhs._value) < delta);
149}
150
151template <typename float_t>
152 UHD_INLINE bool operator!=(double lhs, fp_compare_delta<float_t> rhs)
153{
154 return !(lhs == rhs);
155}
156
157template <typename float_t>
158 UHD_INLINE bool operator<(double lhs, fp_compare_delta<float_t> rhs)
159{
160 float_t delta =
161 float_t(fp_compare_select_delta(DOUBLE_PRECISION_DELTA, double(rhs._delta)));
162 return ((rhs._value - lhs) > delta);
163}
164
165template <typename float_t>
166 UHD_INLINE bool operator<=(double lhs, fp_compare_delta<float_t> rhs)
167{
168 return !(lhs > rhs);
169}
170
171template <typename float_t>
172 UHD_INLINE bool operator>(double lhs, fp_compare_delta<float_t> rhs)
173{
174 float_t delta =
175 float_t(fp_compare_select_delta(DOUBLE_PRECISION_DELTA, double(rhs._delta)));
176 return ((lhs - rhs._value) > delta);
177}
178
179template <typename float_t>
180 UHD_INLINE bool operator>=(double lhs, fp_compare_delta<float_t> rhs)
181{
182 return !(lhs < rhs);
183}
184
185}}} // namespace uhd::math::fp_compare
uhd::math::fp_compare::fp_compare_delta
Definition math.hpp:203
uhd::math::fp_compare::fp_compare_delta::fp_compare_delta
UHD_INLINE fp_compare_delta(float_t value)
uhd::math::fp_compare::fp_compare_delta::_delta
float_t _delta
Definition math.hpp:212
uhd::math::fp_compare::fp_compare_delta::operator=
UHD_INLINE void operator=(const fp_compare_delta &copy)
Definition fp_compare_delta.ipp:56
uhd::math::fp_compare::fp_compare_delta::~fp_compare_delta
UHD_INLINE ~fp_compare_delta()
Definition fp_compare_delta.ipp:51
uhd::math::fp_compare::fp_compare_delta::_value
float_t _value
Definition math.hpp:211
UHD_INLINE
#define UHD_INLINE
Definition config.h:65
uhd::math::fp_compare
Definition fp_compare_delta.ipp:15
uhd::math::fp_compare::fp_compare_select_delta
UHD_INLINE float_t fp_compare_select_delta(float_t lhs_delta, float_t rhs_delta)
Definition fp_compare_delta.ipp:18
uhd::math::fp_compare::operator!=
UHD_INLINE bool operator!=(fp_compare_delta< float_t > lhs, fp_compare_delta< float_t > rhs)
Definition fp_compare_delta.ipp:71
uhd::math::fp_compare::operator<=
UHD_INLINE bool operator<=(fp_compare_delta< float_t > lhs, fp_compare_delta< float_t > rhs)
Definition fp_compare_delta.ipp:84
uhd::math::fp_compare::operator==
UHD_INLINE bool operator==(fp_compare_delta< float_t > lhs, fp_compare_delta< float_t > rhs)
Definition fp_compare_delta.ipp:64
uhd::math::fp_compare::operator<
UHD_INLINE bool operator<(fp_compare_delta< float_t > lhs, fp_compare_delta< float_t > rhs)
Definition fp_compare_delta.ipp:77
uhd::math::fp_compare::operator>
UHD_INLINE bool operator>(fp_compare_delta< float_t > lhs, fp_compare_delta< float_t > rhs)
Definition fp_compare_delta.ipp:90
uhd::math::fp_compare::operator>=
UHD_INLINE bool operator>=(fp_compare_delta< float_t > lhs, fp_compare_delta< float_t > rhs)
Definition fp_compare_delta.ipp:97
uhd::math
Definition fp_compare_delta.ipp:15
uhd
Definition build_info.hpp:12