36 constexpr
int sgn(
const T _value) noexcept {
37 return (T(0) < _value) - (_value < T(0));
43 constexpr T
sqr(
const T &_a) noexcept {
50 constexpr T
pow(
const T& _base,
const uint32 _exp) noexcept {
51 return _exp==0 ? T(1) : (_exp%2==0 ?
pow(T(_base*_base), _exp/2) : T(_base*
pow(_base, _exp-1)));
56 constexpr T
pow(
const T &_base,
const uint64 _exp) noexcept {
57 return _exp==0 ? T(1) : (_exp%2==0 ?
pow(T(_base*_base), _exp/2) : T(_base*
pow(_base, _exp-1)));
63 constexpr T
pow(
const T &_base,
const int64 _exp) noexcept {
68 T( 1/
pow(_base, -_exp))
70 ( _exp%2==0 ?
pow(T(_base*_base), _exp/2) : T(_base*
pow(_base, _exp-1)) )
77 constexpr T
pow(
const T &_base,
const int32 _exp) noexcept {
82 T( 1/
pow(_base, -_exp))
84 ( _exp%2==0 ?
pow(T(_base*_base), _exp/2) : T(_base*
pow(_base, _exp-1)) )
90 template<class T, typename std::enable_if<std::is_floating_point<T>::value,
bool>::type =
true>
91 bool approx_equal(T _a, T
_b, T _eps = 4*std::numeric_limits<T>::epsilon()) noexcept {
92 return std::abs(_a-_b) <= _eps*0.5*(std::abs(_a)+std::abs(_b));
97 template<class T, typename std::enable_if<!std::is_floating_point<T>::value,
bool>::type =
true>
106 #pragma GCC diagnostic push 107 #pragma GCC diagnostic ignored "-Wfloat-equal" 109 #pragma GCC diagnostic pop 116 #pragma GCC diagnostic push 117 #pragma GCC diagnostic ignored "-Wfloat-equal" 119 #pragma GCC diagnostic pop
bool approx_equal(T _a, T _b, T _eps=4 *std::numeric_limits< T >::epsilon()) noexcept
: Checks whether the relative difference between _a and _b (i.e. |a-b|/(|a|/2+|b|/2)) is smaller than...
The main namespace of xerus.
constexpr bool hard_not_equal(const T _a, const T _b) noexcept
: Checks for hard inequality ( != operator) without compiler warnings.
Header file for macros that encapsulate SFINAE functionality.
constexpr T sqr(const T &_a) noexcept
: Calculates _a*_a.
constexpr int sgn(const T _value) noexcept
: Calculates the signum (-1, 0, 1) of a given value.
constexpr bool hard_equal(const T _a, const T _b) noexcept
: Checks for hard equality ( == operator) without compiler warnings.
constexpr T pow(const T &_base, const uint32 _exp) noexcept
: Calculates _base^_exp by binary exponentiation
Header file for global shorthand notations of elementary integer types and attribute lists...