common.inl 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /// @ref gtx_common
  2. #include <cmath>
  3. #include "../gtc/epsilon.hpp"
  4. #include "../gtc/constants.hpp"
  5. namespace glm{
  6. namespace detail
  7. {
  8. template<length_t L, typename T, qualifier Q, bool isFloat = true>
  9. struct compute_fmod
  10. {
  11. GLM_FUNC_QUALIFIER static vec<L, T, Q> call(vec<L, T, Q> const& a, vec<L, T, Q> const& b)
  12. {
  13. return detail::functor2<vec, L, T, Q>::call(std::fmod, a, b);
  14. }
  15. };
  16. template<length_t L, typename T, qualifier Q>
  17. struct compute_fmod<L, T, Q, false>
  18. {
  19. GLM_FUNC_QUALIFIER static vec<L, T, Q> call(vec<L, T, Q> const& a, vec<L, T, Q> const& b)
  20. {
  21. return a % b;
  22. }
  23. };
  24. }//namespace detail
  25. template<typename T>
  26. GLM_FUNC_QUALIFIER bool isdenormal(T const& x)
  27. {
  28. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isdenormal' only accept floating-point inputs");
  29. # if GLM_HAS_CXX11_STL
  30. return std::fpclassify(x) == FP_SUBNORMAL;
  31. # else
  32. return epsilonNotEqual(x, static_cast<T>(0), epsilon<T>()) && std::fabs(x) < std::numeric_limits<T>::min();
  33. # endif
  34. }
  35. template<typename T, qualifier Q>
  36. GLM_FUNC_QUALIFIER typename vec<1, T, Q>::bool_type isdenormal
  37. (
  38. vec<1, T, Q> const& x
  39. )
  40. {
  41. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isdenormal' only accept floating-point inputs");
  42. return typename vec<1, T, Q>::bool_type(
  43. isdenormal(x.x));
  44. }
  45. template<typename T, qualifier Q>
  46. GLM_FUNC_QUALIFIER typename vec<2, T, Q>::bool_type isdenormal
  47. (
  48. vec<2, T, Q> const& x
  49. )
  50. {
  51. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isdenormal' only accept floating-point inputs");
  52. return typename vec<2, T, Q>::bool_type(
  53. isdenormal(x.x),
  54. isdenormal(x.y));
  55. }
  56. template<typename T, qualifier Q>
  57. GLM_FUNC_QUALIFIER typename vec<3, T, Q>::bool_type isdenormal
  58. (
  59. vec<3, T, Q> const& x
  60. )
  61. {
  62. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isdenormal' only accept floating-point inputs");
  63. return typename vec<3, T, Q>::bool_type(
  64. isdenormal(x.x),
  65. isdenormal(x.y),
  66. isdenormal(x.z));
  67. }
  68. template<typename T, qualifier Q>
  69. GLM_FUNC_QUALIFIER typename vec<4, T, Q>::bool_type isdenormal
  70. (
  71. vec<4, T, Q> const& x
  72. )
  73. {
  74. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isdenormal' only accept floating-point inputs");
  75. return typename vec<4, T, Q>::bool_type(
  76. isdenormal(x.x),
  77. isdenormal(x.y),
  78. isdenormal(x.z),
  79. isdenormal(x.w));
  80. }
  81. // fmod
  82. template<typename genType>
  83. GLM_FUNC_QUALIFIER genType fmod(genType x, genType y)
  84. {
  85. return fmod(vec<1, genType>(x), y).x;
  86. }
  87. template<length_t L, typename T, qualifier Q>
  88. GLM_FUNC_QUALIFIER vec<L, T, Q> fmod(vec<L, T, Q> const& x, T y)
  89. {
  90. return detail::compute_fmod<L, T, Q, std::numeric_limits<T>::is_iec559>::call(x, vec<L, T, Q>(y));
  91. }
  92. template<length_t L, typename T, qualifier Q>
  93. GLM_FUNC_QUALIFIER vec<L, T, Q> fmod(vec<L, T, Q> const& x, vec<L, T, Q> const& y)
  94. {
  95. return detail::compute_fmod<L, T, Q, std::numeric_limits<T>::is_iec559>::call(x, y);
  96. }
  97. template <length_t L, typename T, qualifier Q>
  98. GLM_FUNC_QUALIFIER vec<L, bool, Q> openBounded(vec<L, T, Q> const& Value, vec<L, T, Q> const& Min, vec<L, T, Q> const& Max)
  99. {
  100. return greaterThan(Value, Min) && lessThan(Value, Max);
  101. }
  102. template <length_t L, typename T, qualifier Q>
  103. GLM_FUNC_QUALIFIER vec<L, bool, Q> closeBounded(vec<L, T, Q> const& Value, vec<L, T, Q> const& Min, vec<L, T, Q> const& Max)
  104. {
  105. return greaterThanEqual(Value, Min) && lessThanEqual(Value, Max);
  106. }
  107. }//namespace glm