From 38f536049a8ed8f4bdf7706f4afcbbaf06c974c9 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Sat, 29 Oct 2016 18:13:12 +0300 Subject: [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) --- include/mbgl/math/log2.hpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 include/mbgl/math/log2.hpp (limited to 'include/mbgl/math') diff --git a/include/mbgl/math/log2.hpp b/include/mbgl/math/log2.hpp new file mode 100644 index 0000000000..8a3bc7f1c0 --- /dev/null +++ b/include/mbgl/math/log2.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include +#include +#include + +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 std::enable_if_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 -- cgit v1.2.1