You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.0 KiB

  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2009-10-26
  5. // Updated : 2011-06-07
  6. // Licence : This source is under MIT License
  7. // File : glm/gtx/multiple.inl
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. // Dependency:
  10. // - GLM core
  11. ///////////////////////////////////////////////////////////////////////////////////////////////////
  12. namespace glm
  13. {
  14. //////////////////////
  15. // higherMultiple
  16. template <typename genType>
  17. GLM_FUNC_QUALIFIER genType higherMultiple
  18. (
  19. genType const & Source,
  20. genType const & Multiple
  21. )
  22. {
  23. if (Source > 0)
  24. {
  25. genType Tmp = Source - 1;
  26. return Tmp + (Multiple - (Tmp % Multiple));
  27. }
  28. else
  29. return Source + (-Source % Multiple);
  30. }
  31. template <>
  32. GLM_FUNC_QUALIFIER detail::half higherMultiple
  33. (
  34. detail::half const & SourceH,
  35. detail::half const & MultipleH
  36. )
  37. {
  38. float Source = SourceH.toFloat();
  39. float Multiple = MultipleH.toFloat();
  40. int Tmp = int(float(Source)) % int(Multiple);
  41. return detail::half(Tmp ? Source + Multiple - float(Tmp) : Source);
  42. }
  43. template <>
  44. GLM_FUNC_QUALIFIER float higherMultiple
  45. (
  46. float const & Source,
  47. float const & Multiple
  48. )
  49. {
  50. int Tmp = int(Source) % int(Multiple);
  51. return Tmp ? Source + Multiple - float(Tmp) : Source;
  52. }
  53. template <>
  54. GLM_FUNC_QUALIFIER double higherMultiple
  55. (
  56. double const & Source,
  57. double const & Multiple
  58. )
  59. {
  60. long Tmp = long(Source) % long(Multiple);
  61. return Tmp ? Source + Multiple - double(Tmp) : Source;
  62. }
  63. VECTORIZE_VEC_VEC(higherMultiple)
  64. //////////////////////
  65. // lowerMultiple
  66. template <typename genType>
  67. GLM_FUNC_QUALIFIER genType lowerMultiple
  68. (
  69. genType const & Source,
  70. genType const & Multiple
  71. )
  72. {
  73. if (Source >= 0)
  74. return Source - Source % Multiple;
  75. else
  76. {
  77. genType Tmp = Source + 1;
  78. return Tmp - Tmp % Multiple - Multiple;
  79. }
  80. }
  81. template <>
  82. GLM_FUNC_QUALIFIER detail::half lowerMultiple
  83. (
  84. detail::half const & SourceH,
  85. detail::half const & MultipleH
  86. )
  87. {
  88. float Source = SourceH.toFloat();
  89. float Multiple = MultipleH.toFloat();
  90. int Tmp = int(float(Source)) % int(float(Multiple));
  91. return detail::half(Tmp ? Source - float(Tmp) : Source);
  92. }
  93. template <>
  94. GLM_FUNC_QUALIFIER float lowerMultiple
  95. (
  96. float const & Source,
  97. float const & Multiple
  98. )
  99. {
  100. int Tmp = int(Source) % int(Multiple);
  101. return Tmp ? Source - float(Tmp) : Source;
  102. }
  103. template <>
  104. GLM_FUNC_QUALIFIER double lowerMultiple
  105. (
  106. double const & Source,
  107. double const & Multiple
  108. )
  109. {
  110. long Tmp = long(Source) % long(Multiple);
  111. return Tmp ? Source - double(Tmp) : Source;
  112. }
  113. VECTORIZE_VEC_VEC(lowerMultiple)
  114. }//namespace glm