#ifndef BASE_INCLUDE_FLOAT_COMPARISON_H_
#define BASE_INCLUDE_FLOAT_COMPARISON_H_
#include <math.h>
#include <cmath>
namespace lynx {
namespace base {
constexpr float EPSILON = 0.01f;
constexpr float EPSILON_PRECISE = 1e-3;
constexpr double EPSILON_DOUBLE = 1e-6;
inline bool DoublesEqual(const double first, const double second) {
return fabs(first - second) < EPSILON_DOUBLE;
}
inline bool IsZero(const double d) { return DoublesEqual(d, 0.00000L); }
inline bool FloatsEqual(const float first, const float second) {
return fabs(first - second) < EPSILON;
}
inline bool FloatsEqualPrecise(const float first, const float second) {
return fabs(first - second) < EPSILON_PRECISE;
}
inline bool FloatsNotEqual(const float first, const float second) {
return fabs(first - second) >= EPSILON;
}
inline bool FloatsLarger(const float first, const float second) {
return fabs(first - second) >= EPSILON && first > second;
}
inline bool FloatsLargerPrecise(const float first, const float second) {
return fabs(first - second) >= EPSILON_PRECISE && first > second;
}
inline bool FloatsLargerOrEqual(const float first, const float second) {
return first > second || fabs(first - second) < EPSILON;
}
inline bool IsZero(const float f) { return FloatsEqual(f, 0.0f); }
}
}
#endif