diff options
author | Leith Bade <leith@mapbox.com> | 2014-12-05 23:16:49 +1100 |
---|---|---|
committer | Leith Bade <leith@mapbox.com> | 2014-12-05 23:16:49 +1100 |
commit | de9eb00276684a10f49a1c490f55266b80238155 (patch) | |
tree | fc713b06541bb1af04e95c70f2e383bcb86a164a /src/mbgl/util/math.cpp | |
parent | c348c141c5c5754c962d9b7e94af83f097e30487 (diff) | |
parent | ff640132de0fe855314a8fd86adae3a2fb33237b (diff) | |
download | qtlocation-mapboxgl-de9eb00276684a10f49a1c490f55266b80238155.tar.gz |
Merge branch 'master' of github.com:mapbox/mapbox-gl-native into android-mason
Conflicts:
.gitignore
gyp/mbgl-ios.gypi
gyp/mbgl-linux.gypi
gyp/mbgl-osx.gypi
include/mbgl/map/map.hpp
src/mbgl/map/map.cpp
src/mbgl/storage/caching_http_file_source.cpp
Diffstat (limited to 'src/mbgl/util/math.cpp')
-rw-r--r-- | src/mbgl/util/math.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/mbgl/util/math.cpp b/src/mbgl/util/math.cpp new file mode 100644 index 0000000000..a7eab2d771 --- /dev/null +++ b/src/mbgl/util/math.cpp @@ -0,0 +1,25 @@ +#include <mbgl/util/math.hpp> + +namespace mbgl { +namespace util { + +// From http://stackoverflow.com/questions/3272424/compute-fast-log-base-2-ceiling +uint32_t ceil_log2(uint64_t x) { + static const uint64_t t[6] = {0xFFFFFFFF00000000, 0x00000000FFFF0000, + 0x000000000000FF00, 0x00000000000000F0, + 0x000000000000000C, 0x0000000000000002}; + uint32_t y = (((x & (x - 1)) == 0) ? 0 : 1); + uint32_t j = 32; + + for (int32_t i = 0; i < 6; i++) { + const uint32_t k = (((x & t[i]) == 0) ? 0 : j); + y += k; + x >>= k; + j >>= 1; + } + + return y; +} + +} +}
\ No newline at end of file |