vector_integer.inl 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include "scalar_integer.hpp"
  2. namespace glm
  3. {
  4. template<length_t L, typename T, qualifier Q>
  5. GLM_FUNC_QUALIFIER vec<L, bool, Q> isPowerOfTwo(vec<L, T, Q> const& Value)
  6. {
  7. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'isPowerOfTwo' only accept integer inputs");
  8. vec<L, T, Q> const Result(abs(Value));
  9. return equal(Result & (Result - vec<L, T, Q>(1)), vec<L, T, Q>(0));
  10. }
  11. template<length_t L, typename T, qualifier Q>
  12. GLM_FUNC_QUALIFIER vec<L, T, Q> nextPowerOfTwo(vec<L, T, Q> const& v)
  13. {
  14. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'nextPowerOfTwo' only accept integer inputs");
  15. return detail::compute_ceilPowerOfTwo<L, T, Q, std::numeric_limits<T>::is_signed>::call(v);
  16. }
  17. template<length_t L, typename T, qualifier Q>
  18. GLM_FUNC_QUALIFIER vec<L, T, Q> prevPowerOfTwo(vec<L, T, Q> const& v)
  19. {
  20. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'prevPowerOfTwo' only accept integer inputs");
  21. return detail::functor1<vec, L, T, T, Q>::call(prevPowerOfTwo, v);
  22. }
  23. template<length_t L, typename T, qualifier Q>
  24. GLM_FUNC_QUALIFIER vec<L, bool, Q> isMultiple(vec<L, T, Q> const& Value, T Multiple)
  25. {
  26. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'isMultiple' only accept integer inputs");
  27. return (Value % Multiple) == vec<L, T, Q>(0);
  28. }
  29. template<length_t L, typename T, qualifier Q>
  30. GLM_FUNC_QUALIFIER vec<L, bool, Q> isMultiple(vec<L, T, Q> const& Value, vec<L, T, Q> const& Multiple)
  31. {
  32. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'isMultiple' only accept integer inputs");
  33. return (Value % Multiple) == vec<L, T, Q>(0);
  34. }
  35. template<length_t L, typename T, qualifier Q>
  36. GLM_FUNC_QUALIFIER vec<L, T, Q> nextMultiple(vec<L, T, Q> const& Source, T Multiple)
  37. {
  38. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'nextMultiple' only accept integer inputs");
  39. return detail::functor2<vec, L, T, Q>::call(nextMultiple, Source, vec<L, T, Q>(Multiple));
  40. }
  41. template<length_t L, typename T, qualifier Q>
  42. GLM_FUNC_QUALIFIER vec<L, T, Q> nextMultiple(vec<L, T, Q> const& Source, vec<L, T, Q> const& Multiple)
  43. {
  44. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'nextMultiple' only accept integer inputs");
  45. return detail::functor2<vec, L, T, Q>::call(nextMultiple, Source, Multiple);
  46. }
  47. template<length_t L, typename T, qualifier Q>
  48. GLM_FUNC_QUALIFIER vec<L, T, Q> prevMultiple(vec<L, T, Q> const& Source, T Multiple)
  49. {
  50. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'prevMultiple' only accept integer inputs");
  51. return detail::functor2<vec, L, T, Q>::call(prevMultiple, Source, vec<L, T, Q>(Multiple));
  52. }
  53. template<length_t L, typename T, qualifier Q>
  54. GLM_FUNC_QUALIFIER vec<L, T, Q> prevMultiple(vec<L, T, Q> const& Source, vec<L, T, Q> const& Multiple)
  55. {
  56. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'prevMultiple' only accept integer inputs");
  57. return detail::functor2<vec, L, T, Q>::call(prevMultiple, Source, Multiple);
  58. }
  59. template<length_t L, typename T, qualifier Q>
  60. GLM_FUNC_QUALIFIER vec<L, int, Q> findNSB(vec<L, T, Q> const& Source, vec<L, int, Q> SignificantBitCount)
  61. {
  62. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'findNSB' only accept integer inputs");
  63. return detail::functor2_vec_int<L, T, Q>::call(findNSB, Source, SignificantBitCount);
  64. }
  65. }//namespace glm