Browse Source

Add a utility function to compute the power of two above.

legacy
Sam Hocevar sam 14 years ago
parent
commit
c89d05d7e6
1 changed files with 14 additions and 0 deletions
  1. +14
    -0
      src/matrix.h

+ 14
- 0
src/matrix.h View File

@@ -140,5 +140,19 @@ typedef Vec3<int> Int3;
GLOBALS(2)
GLOBALS(3)

/* A few utility functions */
template <typename T> static inline T PotUp(T val)
{
val = val - 1;
//if (sizeof(val) > 8) val = val | (val >> 64);
//if (sizeof(val) > 4) val = val | (val >> 32);
if (sizeof(val) > 2) val = val | (val >> 16);
if (sizeof(val) > 1) val = val | (val >> 8);
val = val | (val >> 4);
val = val | (val >> 2);
val = val | (val >> 1);
return val + 1;
}

#endif // __DH_MATRIX_H__


Loading…
Cancel
Save