#ifndef NUMERIC_H #define NUMERIC_H #include #include #include #include namespace SciQLop::numeric { /* taken from here https://en.cppreference.com/w/cpp/types/numeric_limits/epsilon */ template typename std::enable_if::is_integer, bool>::type almost_equal(T x, T y, int ulp=1) { // the machine epsilon has to be scaled to the magnitude of the values used // and multiplied by the desired precision in ULPs (units in the last place) return std::abs(x-y) <= std::numeric_limits::epsilon() * std::abs(x+y) * ulp // unless the result is subnormal || std::abs(x-y) < std::numeric_limits::min(); } } #endif