diff --git a/glm/gtx/multiple.inl b/glm/gtx/multiple.inl index e644dd8b..e7d25b0f 100644 --- a/glm/gtx/multiple.inl +++ b/glm/gtx/multiple.inl @@ -22,8 +22,13 @@ namespace glm genType const & Multiple ) { - genType Tmp = Source % Multiple; - return Tmp ? Source + Multiple - Tmp : Source; + if (Source > 0) + { + genType Tmp = Source - 1; + return Tmp + (Multiple - (Tmp % Multiple)); + } + else + return Source + (-Source % Multiple); } template <> @@ -74,8 +79,13 @@ namespace glm genType const & Multiple ) { - genType Tmp = Source % Multiple; - return Tmp ? Source - Tmp : Source; + if (Source >= 0) + return Source - Source % Multiple; + else + { + genType Tmp = Source + 1; + return Tmp - Tmp % Multiple - Multiple; + } } template <> diff --git a/test/gtx/gtx_multiple.cpp b/test/gtx/gtx_multiple.cpp index f3f1d394..dd08b55e 100644 --- a/test/gtx/gtx_multiple.cpp +++ b/test/gtx/gtx_multiple.cpp @@ -14,13 +14,16 @@ int test_higher() { int Error(0); - int Higher0 = glm::higherMultiple(-5, 4); - Error += Higher0 == -4 ? 0 : 1; + Error += glm::higherMultiple(-5, 4) == -4 ? 0 : 1; Error += glm::higherMultiple(-4, 4) == -4 ? 0 : 1; - Error += glm::higherMultiple(-3, 4) == -4 ? 0 : 1; - Error += glm::higherMultiple(-2, 4) == -4 ? 0 : 1; - Error += glm::higherMultiple(-1, 4) == -4 ? 0 : 1; + Error += glm::higherMultiple(-3, 4) == 0 ? 0 : 1; + Error += glm::higherMultiple(-2, 4) == 0 ? 0 : 1; + Error += glm::higherMultiple(-1, 4) == 0 ? 0 : 1; + Error += glm::higherMultiple(0, 4) == 0 ? 0 : 1; + Error += glm::higherMultiple(1, 4) == 4 ? 0 : 1; + Error += glm::higherMultiple(2, 4) == 4 ? 0 : 1; + Error += glm::higherMultiple(3, 4) == 4 ? 0 : 1; Error += glm::higherMultiple(4, 4) == 4 ? 0 : 1; Error += glm::higherMultiple(5, 4) == 8 ? 0 : 1; Error += glm::higherMultiple(6, 4) == 8 ? 0 : 1; @@ -35,12 +38,15 @@ int test_Lower() { int Error(0); - Error += glm::lowerMultiple(-5, 4) == -4 ? 0 : 1; + Error += glm::lowerMultiple(-5, 4) == -8 ? 0 : 1; Error += glm::lowerMultiple(-4, 4) == -4 ? 0 : 1; - Error += glm::lowerMultiple(-3, 4) == 0 ? 0 : 1; - Error += glm::lowerMultiple(-2, 4) == 0 ? 0 : 1; - Error += glm::lowerMultiple(-1, 4) == 0 ? 0 : 1; + Error += glm::lowerMultiple(-3, 4) == -4 ? 0 : 1; + Error += glm::lowerMultiple(-2, 4) == -4 ? 0 : 1; + Error += glm::lowerMultiple(-1, 4) == -4 ? 0 : 1; Error += glm::lowerMultiple(0, 4) == 0 ? 0 : 1; + Error += glm::lowerMultiple(1, 4) == 0 ? 0 : 1; + Error += glm::lowerMultiple(2, 4) == 0 ? 0 : 1; + Error += glm::lowerMultiple(3, 4) == 0 ? 0 : 1; Error += glm::lowerMultiple(4, 4) == 4 ? 0 : 1; Error += glm::lowerMultiple(5, 4) == 4 ? 0 : 1; Error += glm::lowerMultiple(6, 4) == 4 ? 0 : 1;