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.

97 lines
1.9 KiB

5 years ago
  1. #include <glm/gtc/ulp.hpp>
  2. #include <glm/gtc/epsilon.hpp>
  3. #include <limits>
  4. int test_ulp_float_dist()
  5. {
  6. int Error = 0;
  7. float A = 1.0f;
  8. float B = glm::next_float(A);
  9. Error += !glm::epsilonEqual(A, B, glm::epsilon<float>()) ? 0 : 1;
  10. float C = glm::prev_float(B);
  11. Error += glm::epsilonEqual(A, C, glm::epsilon<float>()) ? 0 : 1;
  12. int D = glm::float_distance(A, B);
  13. Error += D == 1 ? 0 : 1;
  14. int E = glm::float_distance(A, C);
  15. Error += E == 0 ? 0 : 1;
  16. return Error;
  17. }
  18. int test_ulp_float_step()
  19. {
  20. int Error = 0;
  21. float A = 1.0f;
  22. for(int i = 10; i < 1000; i *= 10)
  23. {
  24. float B = glm::next_float(A, i);
  25. Error += !glm::epsilonEqual(A, B, glm::epsilon<float>()) ? 0 : 1;
  26. float C = glm::prev_float(B, i);
  27. Error += glm::epsilonEqual(A, C, glm::epsilon<float>()) ? 0 : 1;
  28. int D = glm::float_distance(A, B);
  29. Error += D == i ? 0 : 1;
  30. int E = glm::float_distance(A, C);
  31. Error += E == 0 ? 0 : 1;
  32. }
  33. return Error;
  34. }
  35. int test_ulp_double_dist()
  36. {
  37. int Error = 0;
  38. double A = 1.0;
  39. double B = glm::next_float(A);
  40. Error += !glm::epsilonEqual(A, B, glm::epsilon<double>()) ? 0 : 1;
  41. double C = glm::prev_float(B);
  42. Error += glm::epsilonEqual(A, C, glm::epsilon<double>()) ? 0 : 1;
  43. int D = glm::float_distance(A, B);
  44. Error += D == 1 ? 0 : 1;
  45. int E = glm::float_distance(A, C);
  46. Error += E == 0 ? 0 : 1;
  47. return Error;
  48. }
  49. int test_ulp_double_step()
  50. {
  51. int Error = 0;
  52. double A = 1.0;
  53. for(int i = 10; i < 1000; i *= 10)
  54. {
  55. double B = glm::next_float(A, i);
  56. Error += !glm::epsilonEqual(A, B, glm::epsilon<double>()) ? 0 : 1;
  57. double C = glm::prev_float(B, i);
  58. Error += glm::epsilonEqual(A, C, glm::epsilon<double>()) ? 0 : 1;
  59. int D = glm::float_distance(A, B);
  60. Error += D == i ? 0 : 1;
  61. int E = glm::float_distance(A, C);
  62. Error += E == 0 ? 0 : 1;
  63. }
  64. return Error;
  65. }
  66. int main()
  67. {
  68. int Error = 0;
  69. Error += test_ulp_float_dist();
  70. Error += test_ulp_float_step();
  71. Error += test_ulp_double_dist();
  72. Error += test_ulp_double_step();
  73. return Error;
  74. }