blob: 8a3bc7f1c0a334caa5dc7cfe47d0b58a3c8fe716 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#pragma once
#include <cmath>
#include <cstdint>
#include <type_traits>
namespace mbgl {
namespace util {
// Computes the log2(x) rounded up to the next integer.
// (== number of bits required to store x)
uint32_t ceil_log2(uint64_t x);
template <typename T>
typename std::enable_if_t<std::is_floating_point<T>::value, T> log2(T x)
{
// log2() is producing wrong results on ARMv5 binaries
// running on ARMv7+ CPUs.
#if defined(__ANDROID__)
return std::log(x) / M_LN2;
#else
return std::log2(x);
#endif
}
} // namespace util
} // namespace mbgl
|