diff options
author | Martin Braun <martin.braun@ettus.com> | 2021-08-31 11:46:39 +0200 |
---|---|---|
committer | Aaron Rossetto <aaron.rossetto@ni.com> | 2021-10-19 12:21:33 -0700 |
commit | 91c10b66c23178e27bbff0e9173570c63e342736 (patch) | |
tree | b9839cd72aa7ed2aaab52738b0610f81a5c8ac91 /host/include | |
parent | 692a588723ec77b62179b70e17eb157ef1b4ea31 (diff) | |
download | uhd-91c10b66c23178e27bbff0e9173570c63e342736.tar.gz uhd-91c10b66c23178e27bbff0e9173570c63e342736.tar.bz2 uhd-91c10b66c23178e27bbff0e9173570c63e342736.zip |
uhd: math: Add a sign() function
We've been having issues with moving locations of Boost headers for this
function, and it's simple enough to implement ourselves.
Diffstat (limited to 'host/include')
-rw-r--r-- | host/include/uhd/utils/math.hpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/host/include/uhd/utils/math.hpp b/host/include/uhd/utils/math.hpp index becc256f1..4918ddf2e 100644 --- a/host/include/uhd/utils/math.hpp +++ b/host/include/uhd/utils/math.hpp @@ -263,6 +263,21 @@ inline IntegerType gcd(IntegerType x, IntegerType y) return _bmint::gcd<IntegerType>(x, y); } +//! Returns the sign of x +// +// Note: This is equivalent to the Boost.Math version, but without the +// dependency. +// +// Returns +1 for positive arguments, -1 for negative arguments, and 0 if x is +// zero. +template <typename T> +inline constexpr int sign(T x) +{ + // Note: If T is unsigned, then this will compile with a warning. Should + // we need that, expand the template logic. + return (T(0) < x) - (x < T(0)); +} + } // namespace math } // namespace uhd |