#include #include #include "stdc.h" #include "util.h" namespace AHFinderDirect { namespace jtutil { template bool fuzzy::EQ(fp_t x, fp_t y) { fp_t max_abs = jtutil::tmax(jtutil::abs(x), jtutil::abs(y)); fp_t epsilon = jtutil::tmax(tolerance_, tolerance_ * max_abs); return jtutil::abs(x - y) <= epsilon; } //****************************************************************************** template bool fuzzy::is_integer(fp_t x) { int i = round::to_integer(x); return EQ(x, fp_t(i)); } //****************************************************************************** template int fuzzy::floor(fp_t x) { return fuzzy::is_integer(x) ? round::to_integer(x) : round::floor(x); } //****************************************************************************** template int fuzzy::ceiling(fp_t x) { return fuzzy::is_integer(x) ? round::to_integer(x) : round::ceiling(x); } template <> float fuzzy::tolerance_ = 1.0e-5; // about 100 * FLT_EPSILON template <> double fuzzy::tolerance_ = 1.0e-12; // about 1e4 * DBL_EPSILON // template instantiations template class fuzzy; template class fuzzy; //****************************************************************************** //****************************************************************************** //****************************************************************************** } // namespace jtutil } // namespace AHFinderDirect