1/////////////////////////////////////////////////////////////////////////////////////////////////// 2// OpenGL Mathematics Copyright (c) 2005 - 2014 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 13namespace glm{ 14namespace detail 15{ 16 template <bool Signed> 17 struct higherMultiple 18 { 19 template <typename genType> 20 GLM_FUNC_QUALIFIER genType operator() 21 ( 22 genType const & Source, 23 genType const & Multiple 24 ) 25 { 26 if (Source > genType(0)) 27 { 28 genType Tmp = Source - genType(1); 29 return Tmp + (Multiple - (Tmp % Multiple)); 30 } 31 else 32 return Source + (-Source % Multiple); 33 } 34 }; 35 36 template <> 37 struct higherMultiple<false> 38 { 39 template <typename genType> 40 GLM_FUNC_QUALIFIER genType operator() 41 ( 42 genType const & Source, 43 genType const & Multiple 44 ) 45 { 46 genType Tmp = Source - genType(1); 47 return Tmp + (Multiple - (Tmp % Multiple)); 48 } 49 }; 50}//namespace detail 51 52 ////////////////////// 53 // higherMultiple 54 55 template <typename genType> 56 GLM_FUNC_QUALIFIER genType higherMultiple 57 ( 58 genType const & Source, 59 genType const & Multiple 60 ) 61 { 62 detail::higherMultiple<std::numeric_limits<genType>::is_signed> Compute; 63 return Compute(Source, Multiple); 64 } 65 66 template <> 67 GLM_FUNC_QUALIFIER float higherMultiple 68 ( 69 float const & Source, 70 float const & Multiple 71 ) 72 { 73 if (Source > float(0)) 74 { 75 float Tmp = Source - float(1); 76 return Tmp + (Multiple - std::fmod(Tmp, Multiple)); 77 } 78 else 79 return Source + std::fmod(-Source, Multiple); 80 } 81 82 template <> 83 GLM_FUNC_QUALIFIER double higherMultiple 84 ( 85 double const & Source, 86 double const & Multiple 87 ) 88 { 89 if (Source > double(0)) 90 { 91 double Tmp = Source - double(1); 92 return Tmp + (Multiple - std::fmod(Tmp, Multiple)); 93 } 94 else 95 return Source + std::fmod(-Source, Multiple); 96 } 97 98 VECTORIZE_VEC_VEC(higherMultiple) 99 100 ////////////////////// 101 // lowerMultiple 102 103 template <typename genType> 104 GLM_FUNC_QUALIFIER genType lowerMultiple 105 ( 106 genType const & Source, 107 genType const & Multiple 108 ) 109 { 110 if (Source >= genType(0)) 111 return Source - Source % Multiple; 112 else 113 { 114 genType Tmp = Source + genType(1); 115 return Tmp - Tmp % Multiple - Multiple; 116 } 117 } 118 119 template <> 120 GLM_FUNC_QUALIFIER float lowerMultiple 121 ( 122 float const & Source, 123 float const & Multiple 124 ) 125 { 126 if (Source >= float(0)) 127 return Source - std::fmod(Source, Multiple); 128 else 129 { 130 float Tmp = Source + float(1); 131 return Tmp - std::fmod(Tmp, Multiple) - Multiple; 132 } 133 } 134 135 template <> 136 GLM_FUNC_QUALIFIER double lowerMultiple 137 ( 138 double const & Source, 139 double const & Multiple 140 ) 141 { 142 if (Source >= double(0)) 143 return Source - std::fmod(Source, Multiple); 144 else 145 { 146 double Tmp = Source + double(1); 147 return Tmp - std::fmod(Tmp, Multiple) - Multiple; 148 } 149 } 150 151 VECTORIZE_VEC_VEC(lowerMultiple) 152}//namespace glm 153