vector_relational.inl 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "../vector_relational.hpp"
  2. #include "../common.hpp"
  3. #include "../detail/qualifier.hpp"
  4. #include "../detail/type_float.hpp"
  5. namespace glm
  6. {
  7. template<length_t L, typename T, qualifier Q>
  8. GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<L, bool, Q> equal(vec<L, T, Q> const& x, vec<L, T, Q> const& y, T Epsilon)
  9. {
  10. return equal(x, y, vec<L, T, Q>(Epsilon));
  11. }
  12. template<length_t L, typename T, qualifier Q>
  13. GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<L, bool, Q> equal(vec<L, T, Q> const& x, vec<L, T, Q> const& y, vec<L, T, Q> const& Epsilon)
  14. {
  15. return lessThanEqual(abs(x - y), Epsilon);
  16. }
  17. template<length_t L, typename T, qualifier Q>
  18. GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<L, bool, Q> notEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y, T Epsilon)
  19. {
  20. return notEqual(x, y, vec<L, T, Q>(Epsilon));
  21. }
  22. template<length_t L, typename T, qualifier Q>
  23. GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<L, bool, Q> notEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y, vec<L, T, Q> const& Epsilon)
  24. {
  25. return greaterThan(abs(x - y), Epsilon);
  26. }
  27. template<length_t L, typename T, qualifier Q>
  28. GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<L, bool, Q> equal(vec<L, T, Q> const& x, vec<L, T, Q> const& y, int MaxULPs)
  29. {
  30. return equal(x, y, vec<L, int, Q>(MaxULPs));
  31. }
  32. template<length_t L, typename T, qualifier Q>
  33. GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<L, bool, Q> equal(vec<L, T, Q> const& x, vec<L, T, Q> const& y, vec<L, int, Q> const& MaxULPs)
  34. {
  35. vec<L, bool, Q> Result(false);
  36. for(length_t i = 0; i < L; ++i)
  37. {
  38. detail::float_t<T> const a(x[i]);
  39. detail::float_t<T> const b(y[i]);
  40. // Different signs means they do not match.
  41. if(a.negative() != b.negative())
  42. {
  43. // Check for equality to make sure +0==-0
  44. Result[i] = a.mantissa() == b.mantissa() && a.exponent() == b.exponent();
  45. }
  46. else
  47. {
  48. // Find the difference in ULPs.
  49. typename detail::float_t<T>::int_type const DiffULPs = abs(a.i - b.i);
  50. Result[i] = DiffULPs <= MaxULPs[i];
  51. }
  52. }
  53. return Result;
  54. }
  55. template<length_t L, typename T, qualifier Q>
  56. GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<L, bool, Q> notEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y, int MaxULPs)
  57. {
  58. return notEqual(x, y, vec<L, int, Q>(MaxULPs));
  59. }
  60. template<length_t L, typename T, qualifier Q>
  61. GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<L, bool, Q> notEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y, vec<L, int, Q> const& MaxULPs)
  62. {
  63. return not_(equal(x, y, MaxULPs));
  64. }
  65. }//namespace glm