core_func_exponential.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. ///////////////////////////////////////////////////////////////////////////////////
  2. /// OpenGL Mathematics (glm.g-truc.net)
  3. ///
  4. /// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net)
  5. /// Permission is hereby granted, free of charge, to any person obtaining a copy
  6. /// of this software and associated documentation files (the "Software"), to deal
  7. /// in the Software without restriction, including without limitation the rights
  8. /// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. /// copies of the Software, and to permit persons to whom the Software is
  10. /// furnished to do so, subject to the following conditions:
  11. ///
  12. /// The above copyright notice and this permission notice shall be included in
  13. /// all copies or substantial portions of the Software.
  14. ///
  15. /// Restrictions:
  16. /// By making use of the Software for military purposes, you choose to make
  17. /// a Bunny unhappy.
  18. ///
  19. /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. /// THE SOFTWARE.
  26. ///
  27. /// @file test/core/func_exponential.cpp
  28. /// @date 2011-01-15 / 2011-09-13
  29. /// @author Christophe Riccio
  30. ///////////////////////////////////////////////////////////////////////////////////
  31. #include <glm/common.hpp>
  32. #include <glm/exponential.hpp>
  33. #include <glm/gtc/ulp.hpp>
  34. #include <glm/gtc/vec1.hpp>
  35. int test_pow()
  36. {
  37. int Error(0);
  38. float A = glm::pow(10.f, 10.f);
  39. glm::vec1 B = glm::pow(glm::vec1(10.f), glm::vec1(10.f));
  40. glm::vec2 C = glm::pow(glm::vec2(10.f), glm::vec2(10.f));
  41. glm::vec3 D = glm::pow(glm::vec3(10.f), glm::vec3(10.f));
  42. glm::vec4 E = glm::pow(glm::vec4(10.f), glm::vec4(10.f));
  43. return Error;
  44. }
  45. int test_exp()
  46. {
  47. int Error(0);
  48. float A = glm::exp(10.f);
  49. glm::vec1 B = glm::exp(glm::vec1(10.f));
  50. glm::vec2 C = glm::exp(glm::vec2(10.f));
  51. glm::vec3 D = glm::exp(glm::vec3(10.f));
  52. glm::vec4 E = glm::exp(glm::vec4(10.f));
  53. return Error;
  54. }
  55. int test_log()
  56. {
  57. int Error(0);
  58. float A = glm::log(10.f);
  59. glm::vec1 B = glm::log(glm::vec1(10.f));
  60. glm::vec2 C = glm::log(glm::vec2(10.f));
  61. glm::vec3 D = glm::log(glm::vec3(10.f));
  62. glm::vec4 E = glm::log(glm::vec4(10.f));
  63. return Error;
  64. }
  65. int test_exp2()
  66. {
  67. int Error(0);
  68. float A = glm::exp2(10.f);
  69. glm::vec1 B = glm::exp2(glm::vec1(10.f));
  70. glm::vec2 C = glm::exp2(glm::vec2(10.f));
  71. glm::vec3 D = glm::exp2(glm::vec3(10.f));
  72. glm::vec4 E = glm::exp2(glm::vec4(10.f));
  73. return Error;
  74. }
  75. int test_log2()
  76. {
  77. int Error(0);
  78. float A = glm::log2(10.f);
  79. glm::vec1 B = glm::log2(glm::vec1(10.f));
  80. glm::vec2 C = glm::log2(glm::vec2(10.f));
  81. glm::vec3 D = glm::log2(glm::vec3(10.f));
  82. glm::vec4 E = glm::log2(glm::vec4(10.f));
  83. return Error;
  84. }
  85. int test_sqrt()
  86. {
  87. int Error(0);
  88. float A = glm::sqrt(10.f);
  89. glm::vec1 B = glm::sqrt(glm::vec1(10.f));
  90. glm::vec2 C = glm::sqrt(glm::vec2(10.f));
  91. glm::vec3 D = glm::sqrt(glm::vec3(10.f));
  92. glm::vec4 E = glm::sqrt(glm::vec4(10.f));
  93. return Error;
  94. }
  95. int test_inversesqrt()
  96. {
  97. int Error(0);
  98. glm::uint ulp(0);
  99. float diff(0.0f);
  100. for(float f = 0.001f; f < 10.f; f *= 1.001f)
  101. {
  102. glm::lowp_fvec1 u(f);
  103. glm::lowp_fvec1 lowp_v = glm::inversesqrt(u);
  104. float defaultp_v = glm::inversesqrt(f);
  105. ulp = glm::max(glm::float_distance(lowp_v.x, defaultp_v), ulp);
  106. diff = glm::abs(lowp_v.x - defaultp_v);
  107. }
  108. return Error;
  109. }
  110. int main()
  111. {
  112. int Error(0);
  113. Error += test_pow();
  114. Error += test_exp();
  115. Error += test_log();
  116. Error += test_exp2();
  117. Error += test_log2();
  118. Error += test_sqrt();
  119. Error += test_inversesqrt();
  120. return Error;
  121. }