summaryrefslogtreecommitdiff
path: root/include/mbgl/math
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-10-29 18:13:12 +0300
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-10-31 16:53:07 +0200
commit38f536049a8ed8f4bdf7706f4afcbbaf06c974c9 (patch)
treef65bb6ad0ebde1840e523b18d539f122548194ab /include/mbgl/math
parenta70bfd89108cf1aef75181819ae43e550a69255e (diff)
downloadqtlocation-mapboxgl-38f536049a8ed8f4bdf7706f4afcbbaf06c974c9.tar.gz
[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)
Diffstat (limited to 'include/mbgl/math')
-rw-r--r--include/mbgl/math/log2.hpp27
1 files changed, 27 insertions, 0 deletions
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 <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