25 #ifndef JAU_BASIC_FLOAT_MATH_HPP_
26 #define JAU_BASIC_FLOAT_MATH_HPP_
29 #include <type_traits>
47 bool in_range(
const T& a,
const T& b,
const T& delta)
49 const T diff = std::fabs(a-b);
50 return diff <= delta ||
51 diff < std::numeric_limits<T>::min();
61 typename std::enable_if<!std::numeric_limits<T>::is_integer, T>::type
68 }
while (one + (x /= two) > one);
82 typename std::enable_if<!std::numeric_limits<T>::is_integer,
bool>::type
83 machine_equal(
const T& a,
const T& b,
int ulp=1,
const T& epsilon=std::numeric_limits<T>::epsilon())
85 const T diff = std::fabs(a-b);
86 return diff <= epsilon * ulp ||
87 diff < std::numeric_limits<T>::min();
101 typename std::enable_if<!std::numeric_limits<T>::is_integer,
bool>::type
102 almost_equal(
const T& a,
const T& b,
int ulp=1,
const T& epsilon=std::numeric_limits<T>::epsilon())
104 const T diff = std::fabs(a-b);
105 return diff <= epsilon * std::fabs(a+b) * ulp ||
106 diff < std::numeric_limits<T>::min();