12 #ifndef HAMMER_MATH_UTILS
13 #define HAMMER_MATH_UTILS
25 inline bool isZero(
const std::complex<double> val) {
26 return ((fabs(val.real()) < std::numeric_limits<double>::min()) &&
27 (fabs(val.imag()) < std::numeric_limits<double>::min()));
34 inline bool isZero(
const double val) {
35 return (fabs(val) < std::numeric_limits<double>::min());
42 inline bool fuzzyLess(
const double val1,
const double val2) {
43 return (val1-val2 < -1.*std::max(
precision, std::numeric_limits<double>::min()));
50 double compareVals(
const double val1,
const double val2);
56 std::complex<double>
compareVals(
const std::complex<double> val1,
const std::complex<double> val2);
59 inline double regularize(
const double regularVal,
const double problematicValue,
60 const double delta = std::numeric_limits<double>::min(),
int direction = 0) {
61 if (fabs(problematicValue - regularVal) > delta) {
64 return problematicValue + delta * (direction == 0 ? ((problematicValue > regularVal) ? -1.0 : 1.0) : 1.*direction);
68 typename std::enable_if<std::is_arithmetic<typename std::remove_reference<T>::type>::value,
double>::type
70 return static_cast<double>(value);
74 typename std::enable_if<
75 std::is_same<typename std::remove_reference<typename std::remove_cv<T>::type>::type, std::string>::value,
82 typename std::enable_if<std::is_same<typename std::remove_reference<typename std::remove_cv<T>::type>::type,
83 std::complex<double>>::value,
90 typename std::enable_if<std::is_unsigned<T>::value && std::is_integral<T>::value, T>::type
minPadding(T value) {
98 value =
static_cast<T
>(value >> 1);
std::enable_if< std::is_arithmetic< typename std::remove_reference< T >::type >::value, double >::type toDouble(T value)
double compareVals(const double val1, const double val2)
bool fuzzyLess(const double val1, const double val2)
double regularize(const double regularVal, const double problematicValue, const double delta=std::numeric_limits< double >::min(), int direction=0)
bool isZero(const std::complex< double > val)
std::enable_if< std::is_unsigned< T >::value &&std::is_integral< T >::value, T >::type minPadding(T value)
static const double precision