aboutsummaryrefslogtreecommitdiffstats
path: root/include/mbgl/math/floor.hpp
blob: 692facf5de87f0f4385a20c150ecb136392ac56e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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