13 #include <boost/numeric/conversion/bounds.hpp> 15 #if BOOST_VERSION >= 106700 16 # include <boost/integer/common_factor.hpp> 18 namespace _bmint = boost::integer;
20 # include <boost/math/common_factor.hpp> 21 namespace _bmint = boost::math;
33 static const double PI = 3.14159265358979323846;
51 static const float SINGLE_PRECISION_EPSILON = 1.19e-7f;
52 static const double DOUBLE_PRECISION_EPSILON = 2.22e-16;
62 static constexpr
double FREQ_COMPARE_EPSILON = 1e-12;
64 namespace fp_compare {
79 template <
typename float_t>
108 template <
typename float_t>
111 template <
typename float_t>
114 template <
typename float_t>
117 template <
typename float_t>
120 template <
typename float_t>
123 template <
typename float_t>
129 template <
typename float_t>
131 template <
typename float_t>
133 template <
typename float_t>
134 UHD_INLINE bool operator<(fp_compare_epsilon<float_t> lhs,
double rhs);
135 template <
typename float_t>
136 UHD_INLINE bool operator<=(fp_compare_epsilon<float_t> lhs,
double rhs);
137 template <
typename float_t>
139 template <
typename float_t>
142 template <
typename float_t>
144 template <
typename float_t>
146 template <
typename float_t>
147 UHD_INLINE bool operator<(double lhs, fp_compare_epsilon<float_t> rhs);
148 template <
typename float_t>
149 UHD_INLINE bool operator<=(double lhs, fp_compare_epsilon<float_t> rhs);
150 template <
typename float_t>
152 template <
typename float_t>
180 static const float SINGLE_PRECISION_DELTA = 1e-3f;
181 static const double DOUBLE_PRECISION_DELTA = 1e-5;
184 static const double FREQ_COMPARISON_DELTA_HZ = 0.1;
187 namespace fp_compare {
202 template <
typename float_t>
207 UHD_INLINE fp_compare_delta(float_t value, float_t delta);
216 template <
typename float_t>
218 template <
typename float_t>
220 template <
typename float_t>
222 template <
typename float_t>
224 template <
typename float_t>
226 template <
typename float_t>
231 template <
typename float_t>
233 template <
typename float_t>
235 template <
typename float_t>
236 UHD_INLINE bool operator<(fp_compare_delta<float_t> lhs,
double rhs);
237 template <
typename float_t>
238 UHD_INLINE bool operator<=(fp_compare_delta<float_t> lhs,
double rhs);
239 template <
typename float_t>
241 template <
typename float_t>
244 template <
typename float_t>
246 template <
typename float_t>
248 template <
typename float_t>
249 UHD_INLINE bool operator<(double lhs, fp_compare_delta<float_t> rhs);
250 template <
typename float_t>
251 UHD_INLINE bool operator<=(double lhs, fp_compare_delta<float_t> rhs);
252 template <
typename float_t>
254 template <
typename float_t>
267 return std::pow(10, (dB_val) / 10.0);
272 return 10 * std::log10(val);
277 template <
typename IntegerType>
278 inline IntegerType
lcm(IntegerType x, IntegerType y)
281 return _bmint::lcm<IntegerType>(x, y);
285 template <
typename IntegerType>
286 inline IntegerType
gcd(IntegerType x, IntegerType y)
289 return _bmint::gcd<IntegerType>(x, y);
299 template <
typename T>
304 return (T(0) < x) - (x < T(0));
319 double freq = std::fmod(requested_freq, rate);
320 if (std::abs(freq) > rate / 2.0)
UHD_INLINE bool frequencies_are_equal(double lhs, double rhs)
Definition: math.hpp:259
UHD_INLINE bool operator<=(fp_compare_delta< float_t > lhs, fp_compare_delta< float_t > rhs)
Definition: fp_compare_delta.ipp:84
float_t _value
Definition: math.hpp:212
UHD_INLINE freq_compare_epsilon(const freq_compare_epsilon ©)
Definition: math.hpp:164
UHD_INLINE bool operator>=(fp_compare_delta< float_t > lhs, fp_compare_delta< float_t > rhs)
Definition: fp_compare_delta.ipp:97
IntegerType gcd(IntegerType x, IntegerType y)
Portable version of gcd() across Boost versions.
Definition: math.hpp:286
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:71
An alias for fp_compare_epsilon, but with defaults for frequencies.
Definition: math.hpp:156
double wrap_frequency(const double requested_freq, const double rate)
Return a wrapped frequency that is the equivalent frequency in the first.
Definition: math.hpp:317
float_t _delta
Definition: math.hpp:213
float_t _epsilon
Definition: math.hpp:90
UHD_INLINE freq_compare_epsilon(double value)
Definition: math.hpp:159
Definition: build_info.hpp:12
UHD_INLINE bool operator<(fp_compare_delta< float_t > lhs, fp_compare_delta< float_t > rhs)
Definition: fp_compare_delta.ipp:77
#define UHD_INLINE
Definition: config.h:65
double dB_to_lin(const double dB_val)
Definition: math.hpp:265
UHD_INLINE ~fp_compare_epsilon()
Definition: fp_compare_epsilon.ipp:46
constexpr int sign(T x)
Returns the sign of x.
Definition: math.hpp:300
float_t _value
Definition: math.hpp:89
UHD_INLINE void operator=(const fp_compare_epsilon ©)
Definition: fp_compare_epsilon.ipp:51
UHD_INLINE fp_compare_epsilon(float_t value)
UHD_INLINE bool operator==(fp_compare_delta< float_t > lhs, fp_compare_delta< float_t > rhs)
Definition: fp_compare_delta.ipp:64
double lin_to_dB(const double val)
Definition: math.hpp:270
IntegerType lcm(IntegerType x, IntegerType y)
Portable version of lcm() across Boost versions.
Definition: math.hpp:278