scalar_relational.inl 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "../common.hpp"
  2. #include "../ext/scalar_int_sized.hpp"
  3. #include "../ext/scalar_uint_sized.hpp"
  4. #include "../detail/type_float.hpp"
  5. namespace glm
  6. {
  7. template<typename genType>
  8. GLM_FUNC_QUALIFIER GLM_CONSTEXPR bool equal(genType const& x, genType const& y, genType const& epsilon)
  9. {
  10. return abs(x - y) <= epsilon;
  11. }
  12. template<typename genType>
  13. GLM_FUNC_QUALIFIER GLM_CONSTEXPR bool notEqual(genType const& x, genType const& y, genType const& epsilon)
  14. {
  15. return abs(x - y) > epsilon;
  16. }
  17. template<typename genType>
  18. GLM_FUNC_QUALIFIER GLM_CONSTEXPR bool equal(genType const& x, genType const& y, int MaxULPs)
  19. {
  20. detail::float_t<genType> const a(x);
  21. detail::float_t<genType> const b(y);
  22. // Different signs means they do not match.
  23. if(a.negative() != b.negative())
  24. return false;
  25. // Find the difference in ULPs.
  26. typename detail::float_t<genType>::int_type const DiffULPs = abs(a.i - b.i);
  27. return DiffULPs <= MaxULPs;
  28. }
  29. template<typename genType>
  30. GLM_FUNC_QUALIFIER GLM_CONSTEXPR bool notEqual(genType const& x, genType const& y, int ULPs)
  31. {
  32. return !equal(x, y, ULPs);
  33. }
  34. }//namespace glm