src/Utilities/log2.hh
//------------------------------------------------------------------------------
// Find the integer log2 of an integer (unsigned of course).
// This is a dumb direct method, not fast!
//------------------------------------------------------------------------------
Find the integer log2 of an integer (unsigned of course).
This is a dumb direct method, not fast!
Find the integer log2 of an integer ( unsigned of course ) . This is a dumb direct method not fast!
inline
unsigned
log2(unsigned x) {
  REQUIRE(x > 0);
  unsigned result = 1U;
  while (result < x) result <<= 1;
  result >>= 1;
  ENSURE((1 << result) <= x and x <  (1 << (result + 1)));
  return result;
}
inline unsigned log2 ( unsigned x ) { REQUIRE ( x > 0 ) ; unsigned result = 1U ; while ( result < x ) result <<= 1 ; result >>= 1 ; ENSURE ( ( 1 << result ) <= x and x < ( 1 << ( result + 1 ) ) ) ; return result ; }
Find the integer log2 of an integer (unsigned of course).
Find the integer log2 of an integer ( unsigned of course ) .