Platformer in OpenGL
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.

108 lines
1.9 KiB

5 years ago
  1. #define GLM_ENABLE_EXPERIMENTAL
  2. #include <glm/exponential.hpp>
  3. #include <glm/gtc/epsilon.hpp>
  4. #include <glm/gtx/integer.hpp>
  5. #include <cstdio>
  6. /*
  7. int test_floor_log2()
  8. {
  9. int Error = 0;
  10. for(std::size_t i = 1; i < 1000000; ++i)
  11. {
  12. glm::uint A = glm::floor_log2(glm::uint(i));
  13. glm::uint B = glm::uint(glm::floor(glm::log2(double(i)))); // Will fail with float, lack of accuracy
  14. Error += A == B ? 0 : 1;
  15. assert(!Error);
  16. }
  17. return Error;
  18. }
  19. */
  20. int test_log2()
  21. {
  22. int Error = 0;
  23. for(std::size_t i = 1; i < 24; ++i)
  24. {
  25. glm::uint A = glm::log2(glm::uint(1 << i));
  26. glm::uint B = glm::uint(glm::log2(double(1 << i)));
  27. //Error += glm::equalEpsilon(double(A), B, 1.0) ? 0 : 1;
  28. Error += glm::abs(double(A) - B) <= 24 ? 0 : 1;
  29. assert(!Error);
  30. printf("Log2(%d) error A=%d, B=%d\n", 1 << i, A, B);
  31. }
  32. printf("log2 error=%d\n", Error);
  33. return Error;
  34. }
  35. int test_nlz()
  36. {
  37. int Error = 0;
  38. for(glm::uint i = 1; i < glm::uint(33); ++i)
  39. Error += glm::nlz(i) == glm::uint(31u) - glm::findMSB(i) ? 0 : 1;
  40. //printf("%d, %d\n", glm::nlz(i), 31u - glm::findMSB(i));
  41. return Error;
  42. }
  43. int test_pow_uint()
  44. {
  45. int Error = 0;
  46. glm::uint const p0 = glm::pow(2u, 0u);
  47. Error += p0 == 1u ? 0 : 1;
  48. glm::uint const p1 = glm::pow(2u, 1u);
  49. Error += p1 == 2u ? 0 : 1;
  50. glm::uint const p2 = glm::pow(2u, 2u);
  51. Error += p2 == 4u ? 0 : 1;
  52. return Error;
  53. }
  54. int test_pow_int()
  55. {
  56. int Error = 0;
  57. int const p0 = glm::pow(2, 0u);
  58. Error += p0 == 1 ? 0 : 1;
  59. int const p1 = glm::pow(2, 1u);
  60. Error += p1 == 2 ? 0 : 1;
  61. int const p2 = glm::pow(2, 2u);
  62. Error += p2 == 4 ? 0 : 1;
  63. int const p0n = glm::pow(-2, 0u);
  64. Error += p0n == -1 ? 0 : 1;
  65. int const p1n = glm::pow(-2, 1u);
  66. Error += p1n == -2 ? 0 : 1;
  67. int const p2n = glm::pow(-2, 2u);
  68. Error += p2n == 4 ? 0 : 1;
  69. return Error;
  70. }
  71. int main()
  72. {
  73. int Error = 0;
  74. Error += test_nlz();
  75. // Error += test_floor_log2();
  76. Error += test_log2();
  77. Error += test_pow_uint();
  78. Error += test_pow_int();
  79. return Error;
  80. }