Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

59 righe
1.2 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://sam.zoy.org/projects/COPYING.WTFPL for more details.
  9. //
  10. //
  11. // The Matrix classes
  12. // ------------------
  13. //
  14. #if !defined __LOL_NUMERIC_H__
  15. #define __LOL_NUMERIC_H__
  16. #include <cstdlib>
  17. #include <stdint.h>
  18. namespace lol
  19. {
  20. /* Random float value */
  21. static inline float RandF()
  22. {
  23. using namespace std;
  24. return (float)rand() / RAND_MAX;
  25. }
  26. static inline float RandF(float val)
  27. {
  28. return RandF() * val;
  29. }
  30. static inline float RandF(float min, float max)
  31. {
  32. return min + RandF() * (max - min);
  33. }
  34. /* Next power of two. */
  35. template <typename T> static inline T PotUp(T val)
  36. {
  37. val = val - 1;
  38. if (sizeof(val) > 4) val = val | ((uint64_t)val >> 32);
  39. if (sizeof(val) > 2) val = val | ((uint64_t)val >> 16);
  40. if (sizeof(val) > 1) val = val | ((uint64_t)val >> 8);
  41. val = val | ((uint64_t)val >> 4);
  42. val = val | ((uint64_t)val >> 2);
  43. val = val | ((uint64_t)val >> 1);
  44. return val + 1;
  45. }
  46. } /* namespace lol */
  47. #endif // __LOL_NUMERIC_H__