Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
826 B

  1. //===== Copyright � 1996-2009, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #ifndef BITTOOLS_H
  8. #define BITTOOLS_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. namespace bittools
  13. {
  14. template<int N, int C = 0>
  15. struct RecurseBit
  16. {
  17. enum {result = RecurseBit<N/2, C+1>::result};
  18. };
  19. template<int C>
  20. struct RecurseBit<0, C>
  21. {
  22. enum {result = C};
  23. };
  24. template<int N, int C = 1>
  25. struct RecursePow2
  26. {
  27. enum {result = RecursePow2<N/2, C*2>::result};
  28. };
  29. template<int C>
  30. struct RecursePow2<0, C>
  31. {
  32. enum {result = C};
  33. };
  34. }
  35. #define ROUND_TO_POWER_OF_2( n ) ( bittools::RecursePow2< (n) - 1 >::result )
  36. #define MINIMUM_BITS_NEEDED( n ) ( bittools::RecurseBit< (n) - 1 >::result )
  37. #endif //BITTOOLS_H