diff --git a/glm/ext/vector_integer.inl b/glm/ext/vector_integer.inl index 4da314b6..d74780a5 100644 --- a/glm/ext/vector_integer.inl +++ b/glm/ext/vector_integer.inl @@ -6,7 +6,7 @@ namespace glm GLM_FUNC_QUALIFIER vec isPowerOfTwo(vec const& Value) { vec const Result(abs(Value)); - return equal(Result & (Result - 1), vec(0)); + return equal(Result & (Result - vec(1)), vec(0)); } template diff --git a/test/ext/ext_vector_integer.cpp b/test/ext/ext_vector_integer.cpp index 278379a6..d1739c84 100644 --- a/test/ext/ext_vector_integer.cpp +++ b/test/ext/ext_vector_integer.cpp @@ -14,6 +14,7 @@ namespace isPowerOfTwo bool Return; }; + template int test_int16() { type const Data[] = @@ -30,13 +31,14 @@ namespace isPowerOfTwo for (std::size_t i = 0, n = sizeof(Data) / sizeof(type); i < n; ++i) { - bool Result = glm::isPowerOfTwo(Data[i].Value); - Error += Data[i].Return == Result ? 0 : 1; + glm::vec const Result = glm::isPowerOfTwo(glm::vec(Data[i].Value)); + Error += glm::vec(Data[i].Return) == Result ? 0 : 1; } return Error; } + template int test_uint16() { type const Data[] = @@ -53,13 +55,14 @@ namespace isPowerOfTwo for (std::size_t i = 0, n = sizeof(Data) / sizeof(type); i < n; ++i) { - bool Result = glm::isPowerOfTwo(Data[i].Value); - Error += Data[i].Return == Result ? 0 : 1; + glm::vec const Result = glm::isPowerOfTwo(glm::vec(Data[i].Value)); + Error += glm::vec(Data[i].Return) == Result ? 0 : 1; } return Error; } + template int test_int32() { type const Data[] = @@ -76,13 +79,14 @@ namespace isPowerOfTwo for (std::size_t i = 0, n = sizeof(Data) / sizeof(type); i < n; ++i) { - bool Result = glm::isPowerOfTwo(Data[i].Value); - Error += Data[i].Return == Result ? 0 : 1; + glm::vec const Result = glm::isPowerOfTwo(glm::vec(Data[i].Value)); + Error += glm::vec(Data[i].Return) == Result ? 0 : 1; } return Error; } + template int test_uint32() { type const Data[] = @@ -99,8 +103,8 @@ namespace isPowerOfTwo for (std::size_t i = 0, n = sizeof(Data) / sizeof(type); i < n; ++i) { - bool Result = glm::isPowerOfTwo(Data[i].Value); - Error += Data[i].Return == Result ? 0 : 1; + glm::vec const Result = glm::isPowerOfTwo(glm::vec(Data[i].Value)); + Error += glm::vec(Data[i].Return) == Result ? 0 : 1; } return Error; @@ -110,10 +114,25 @@ namespace isPowerOfTwo { int Error = 0; - Error += test_int16(); - Error += test_uint16(); - Error += test_int32(); - Error += test_uint32(); + Error += test_int16<1>(); + Error += test_int16<2>(); + Error += test_int16<3>(); + Error += test_int16<4>(); + + Error += test_uint16<1>(); + Error += test_uint16<2>(); + Error += test_uint16<3>(); + Error += test_uint16<4>(); + + Error += test_int32<1>(); + Error += test_int32<2>(); + Error += test_int32<3>(); + Error += test_int32<4>(); + + Error += test_uint32<1>(); + Error += test_uint32<2>(); + Error += test_uint32<3>(); + Error += test_uint32<4>(); return Error; } @@ -121,22 +140,22 @@ namespace isPowerOfTwo namespace prevPowerOfTwo { - template + template int run() { int Error = 0; - T const A = glm::prevPowerOfTwo(static_cast(7)); - Error += A == static_cast(4) ? 0 : 1; + glm::vec const A = glm::prevPowerOfTwo(glm::vec(7)); + Error += A == glm::vec(4) ? 0 : 1; - T const B = glm::prevPowerOfTwo(static_cast(15)); - Error += B == static_cast(8) ? 0 : 1; + glm::vec const B = glm::prevPowerOfTwo(glm::vec(15)); + Error += B == glm::vec(8) ? 0 : 1; - T const C = glm::prevPowerOfTwo(static_cast(31)); - Error += C == static_cast(16) ? 0 : 1; + glm::vec const C = glm::prevPowerOfTwo(glm::vec(31)); + Error += C == glm::vec(16) ? 0 : 1; - T const D = glm::prevPowerOfTwo(static_cast(32)); - Error += D == static_cast(32) ? 0 : 1; + glm::vec const D = glm::prevPowerOfTwo(glm::vec(32)); + Error += D == glm::vec(32) ? 0 : 1; return Error; } @@ -145,15 +164,45 @@ namespace prevPowerOfTwo { int Error = 0; - Error += run(); - Error += run(); - Error += run(); - Error += run(); + Error += run<1, glm::int8>(); + Error += run<2, glm::int8>(); + Error += run<3, glm::int8>(); + Error += run<4, glm::int8>(); - Error += run(); - Error += run(); - Error += run(); - Error += run(); + Error += run<1, glm::int16>(); + Error += run<2, glm::int16>(); + Error += run<3, glm::int16>(); + Error += run<4, glm::int16>(); + + Error += run<1, glm::int32>(); + Error += run<2, glm::int32>(); + Error += run<3, glm::int32>(); + Error += run<4, glm::int32>(); + + Error += run<1, glm::int64>(); + Error += run<2, glm::int64>(); + Error += run<3, glm::int64>(); + Error += run<4, glm::int64>(); + + Error += run<1, glm::uint8>(); + Error += run<2, glm::uint8>(); + Error += run<3, glm::uint8>(); + Error += run<4, glm::uint8>(); + + Error += run<1, glm::uint16>(); + Error += run<2, glm::uint16>(); + Error += run<3, glm::uint16>(); + Error += run<4, glm::uint16>(); + + Error += run<1, glm::uint32>(); + Error += run<2, glm::uint32>(); + Error += run<3, glm::uint32>(); + Error += run<4, glm::uint32>(); + + Error += run<1, glm::uint64>(); + Error += run<2, glm::uint64>(); + Error += run<3, glm::uint64>(); + Error += run<4, glm::uint64>(); return Error; } @@ -161,22 +210,22 @@ namespace prevPowerOfTwo namespace nextPowerOfTwo { - template + template int run() { int Error = 0; - T const A = glm::nextPowerOfTwo(static_cast(7)); - Error += A == static_cast(8) ? 0 : 1; + glm::vec const A = glm::nextPowerOfTwo(glm::vec(7)); + Error += A == glm::vec(8) ? 0 : 1; - T const B = glm::nextPowerOfTwo(static_cast(15)); - Error += B == static_cast(16) ? 0 : 1; + glm::vec const B = glm::nextPowerOfTwo(glm::vec(15)); + Error += B == glm::vec(16) ? 0 : 1; - T const C = glm::nextPowerOfTwo(static_cast(31)); - Error += C == static_cast(32) ? 0 : 1; + glm::vec const C = glm::nextPowerOfTwo(glm::vec(31)); + Error += C == glm::vec(32) ? 0 : 1; - T const D = glm::nextPowerOfTwo(static_cast(32)); - Error += D == static_cast(32) ? 0 : 1; + glm::vec const D = glm::nextPowerOfTwo(glm::vec(32)); + Error += D == glm::vec(32) ? 0 : 1; return Error; } @@ -185,15 +234,45 @@ namespace nextPowerOfTwo { int Error = 0; - Error += run(); - Error += run(); - Error += run(); - Error += run(); + Error += run<1, glm::int8>(); + Error += run<2, glm::int8>(); + Error += run<3, glm::int8>(); + Error += run<4, glm::int8>(); - Error += run(); - Error += run(); - Error += run(); - Error += run(); + Error += run<1, glm::int16>(); + Error += run<2, glm::int16>(); + Error += run<3, glm::int16>(); + Error += run<4, glm::int16>(); + + Error += run<1, glm::int32>(); + Error += run<2, glm::int32>(); + Error += run<3, glm::int32>(); + Error += run<4, glm::int32>(); + + Error += run<1, glm::int64>(); + Error += run<2, glm::int64>(); + Error += run<3, glm::int64>(); + Error += run<4, glm::int64>(); + + Error += run<1, glm::uint8>(); + Error += run<2, glm::uint8>(); + Error += run<3, glm::uint8>(); + Error += run<4, glm::uint8>(); + + Error += run<1, glm::uint16>(); + Error += run<2, glm::uint16>(); + Error += run<3, glm::uint16>(); + Error += run<4, glm::uint16>(); + + Error += run<1, glm::uint32>(); + Error += run<2, glm::uint32>(); + Error += run<3, glm::uint32>(); + Error += run<4, glm::uint32>(); + + Error += run<1, glm::uint64>(); + Error += run<2, glm::uint64>(); + Error += run<3, glm::uint64>(); + Error += run<4, glm::uint64>(); return Error; } @@ -209,7 +288,7 @@ namespace prevMultiple genIUType Return; }; - template + template int run() { type const Data[] = @@ -222,8 +301,11 @@ namespace prevMultiple for (std::size_t i = 0, n = sizeof(Data) / sizeof(type); i < n; ++i) { - glm::vec<4, T> const Result = glm::prevMultiple(glm::vec<4, T>(Data[i].Source), Data[i].Multiple); - Error += glm::vec<4, T>(Data[i].Return) == Result ? 0 : 1; + glm::vec const Result0 = glm::prevMultiple(glm::vec(Data[i].Source), Data[i].Multiple); + Error += glm::vec(Data[i].Return) == Result0 ? 0 : 1; + + glm::vec const Result1 = glm::prevMultiple(glm::vec(Data[i].Source), glm::vec(Data[i].Multiple)); + Error += glm::vec(Data[i].Return) == Result1 ? 0 : 1; } return Error; @@ -233,15 +315,45 @@ namespace prevMultiple { int Error = 0; - Error += run(); - Error += run(); - Error += run(); - Error += run(); + Error += run<1, glm::int8>(); + Error += run<2, glm::int8>(); + Error += run<3, glm::int8>(); + Error += run<4, glm::int8>(); - Error += run(); - Error += run(); - Error += run(); - Error += run(); + Error += run<1, glm::int16>(); + Error += run<2, glm::int16>(); + Error += run<3, glm::int16>(); + Error += run<4, glm::int16>(); + + Error += run<1, glm::int32>(); + Error += run<2, glm::int32>(); + Error += run<3, glm::int32>(); + Error += run<4, glm::int32>(); + + Error += run<1, glm::int64>(); + Error += run<2, glm::int64>(); + Error += run<3, glm::int64>(); + Error += run<4, glm::int64>(); + + Error += run<1, glm::uint8>(); + Error += run<2, glm::uint8>(); + Error += run<3, glm::uint8>(); + Error += run<4, glm::uint8>(); + + Error += run<1, glm::uint16>(); + Error += run<2, glm::uint16>(); + Error += run<3, glm::uint16>(); + Error += run<4, glm::uint16>(); + + Error += run<1, glm::uint32>(); + Error += run<2, glm::uint32>(); + Error += run<3, glm::uint32>(); + Error += run<4, glm::uint32>(); + + Error += run<1, glm::uint64>(); + Error += run<2, glm::uint64>(); + Error += run<3, glm::uint64>(); + Error += run<4, glm::uint64>(); return Error; } @@ -257,21 +369,28 @@ namespace nextMultiple genIUType Return; }; - template + template int run() { type const Data[] = { - { 8, 3, 6 }, - { 7, 7, 7 } + { 3, 4, 4 }, + { 6, 3, 6 }, + { 5, 3, 6 }, + { 7, 7, 7 }, + { 0, 1, 0 }, + { 8, 3, 9 } }; int Error = 0; for (std::size_t i = 0, n = sizeof(Data) / sizeof(type); i < n; ++i) { - glm::vec<4, T> const Result = glm::nextMultiple(glm::vec<4, T>(Data[i].Source), Data[i].Multiple); - Error += glm::vec<4, T>(Data[i].Return) == Result ? 0 : 1; + glm::vec const Result0 = glm::nextMultiple(glm::vec(Data[i].Source), glm::vec(Data[i].Multiple)); + Error += glm::vec(Data[i].Return) == Result0 ? 0 : 1; + + glm::vec const Result1 = glm::nextMultiple(glm::vec(Data[i].Source), Data[i].Multiple); + Error += glm::vec(Data[i].Return) == Result1 ? 0 : 1; } return Error; @@ -281,15 +400,45 @@ namespace nextMultiple { int Error = 0; - Error += run(); - Error += run(); - Error += run(); - Error += run(); + Error += run<1, glm::int8>(); + Error += run<2, glm::int8>(); + Error += run<3, glm::int8>(); + Error += run<4, glm::int8>(); - Error += run(); - Error += run(); - Error += run(); - Error += run(); + Error += run<1, glm::int16>(); + Error += run<2, glm::int16>(); + Error += run<3, glm::int16>(); + Error += run<4, glm::int16>(); + + Error += run<1, glm::int32>(); + Error += run<2, glm::int32>(); + Error += run<3, glm::int32>(); + Error += run<4, glm::int32>(); + + Error += run<1, glm::int64>(); + Error += run<2, glm::int64>(); + Error += run<3, glm::int64>(); + Error += run<4, glm::int64>(); + + Error += run<1, glm::uint8>(); + Error += run<2, glm::uint8>(); + Error += run<3, glm::uint8>(); + Error += run<4, glm::uint8>(); + + Error += run<1, glm::uint16>(); + Error += run<2, glm::uint16>(); + Error += run<3, glm::uint16>(); + Error += run<4, glm::uint16>(); + + Error += run<1, glm::uint32>(); + Error += run<2, glm::uint32>(); + Error += run<3, glm::uint32>(); + Error += run<4, glm::uint32>(); + + Error += run<1, glm::uint64>(); + Error += run<2, glm::uint64>(); + Error += run<3, glm::uint64>(); + Error += run<4, glm::uint64>(); return Error; }