scalar_relational.inl 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. {
  25. // Check for equality to make sure +0==-0
  26. return a.mantissa() == b.mantissa() && a.exponent() == b.exponent();
  27. }
  28. // Find the difference in ULPs.
  29. typename detail::float_t<genType>::int_type const DiffULPs = abs(a.i - b.i);
  30. return DiffULPs <= MaxULPs;
  31. }
  32. template<typename genType>
  33. GLM_FUNC_QUALIFIER GLM_CONSTEXPR bool notEqual(genType const& x, genType const& y, int ULPs)
  34. {
  35. return !equal(x, y, ULPs);
  36. }
  37. }//namespace glm