[Bf-blender-cvs] [cbb8bd467b9] functions: better cross platform exponent computation

Jacques Lucke noreply at git.blender.org
Wed May 22 17:32:47 CEST 2019


Commit: cbb8bd467b9234131d257aa82937a24340da65fa
Author: Jacques Lucke
Date:   Wed May 22 17:31:43 2019 +0200
Branches: functions
https://developer.blender.org/rBcbb8bd467b9234131d257aa82937a24340da65fa

better cross platform exponent computation

===================================================================

M	source/blender/blenlib/BLI_array_lookup.hpp

===================================================================

diff --git a/source/blender/blenlib/BLI_array_lookup.hpp b/source/blender/blenlib/BLI_array_lookup.hpp
index b7421ac119d..11eddce364d 100644
--- a/source/blender/blenlib/BLI_array_lookup.hpp
+++ b/source/blender/blenlib/BLI_array_lookup.hpp
@@ -56,7 +56,12 @@ template<typename Key,
          typename Index = int>
 class ArrayLookup {
  private:
-  static const uint N_EXP = (uint)std::ceil(std::log2(N)) + 1;
+  static constexpr uint calc_exp(uint n)
+  {
+    return (n > 0) ? 1 + calc_exp(n >> 1) : 0;
+  }
+
+  static const uint N_EXP = calc_exp(N);
   using Mapping = SmallVector<Index, (1 << N_EXP)>;
 
   Mapping m_map;



More information about the Bf-blender-cvs mailing list