1 | #pragma once |
2 | |
3 | #include <cmath> |
4 | #include <cstdint> |
5 | #include <type_traits> |
6 | |
7 | #if defined(__ANDROID__) |
8 | #include <android/api-level.h> |
9 | #endif |
10 | |
11 | namespace mbgl { |
12 | namespace util { |
13 | |
14 | // Computes the log2(x) rounded up to the next integer. |
15 | // (== number of bits required to store x) |
16 | uint32_t ceil_log2(uint64_t x); |
17 | |
18 | } // namespace util |
19 | } // namespace mbgl |
20 | |
21 | // log2 is not available on Android before API 18. |
22 | #if defined(__ANDROID__) && defined(__GNUC__) && \ |
23 | defined(__ANDROID_API__) && __ANDROID_API__ < 18 |
24 | |
25 | template <typename T> |
26 | typename std::enable_if_t<std::is_floating_point<T>::value, T> log2(T x) { |
27 | return ::log(x) / M_LN2; |
28 | } |
29 | |
30 | #endif |
31 | |