Files
MapLibreParticleLab/include/mbgl/math/log2.hpp
Bruno de Oliveira Abinader 38f536049a [core] Moved util::log2 to its own header
- Added util::{MIN,MAX}_ZOOM_F to avoid consecutive conversions from
double to float
- Move util::log2 to its own header (part of mbgl/math)
2016-10-31 16:53:07 +02:00

28 lines
558 B
C++

#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