diff options
Diffstat (limited to 'include/mbgl/math/floor.hpp')
-rw-r--r-- | include/mbgl/math/floor.hpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/include/mbgl/math/floor.hpp b/include/mbgl/math/floor.hpp new file mode 100644 index 000000000..692facf5d --- /dev/null +++ b/include/mbgl/math/floor.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include <cmath> +#include <limits> +#include <type_traits> + +namespace mbgl { +namespace util { + +// https://en.cppreference.com/w/cpp/types/numeric_limits/epsilon +template <typename T, typename = std::enable_if<std::is_floating_point<T>::value>> +T floor(T a) { + return ::fabs(a) <= std::numeric_limits<T>::epsilon() ? 0 : ::floor(a); +} + +} // namespace util +} // namespace mbgl |