mirror of
https://github.com/g-truc/glm.git
synced 2024-11-23 01:14:34 +00:00
- Fixed integer pow from GTX_integer with null exponent #658
This commit is contained in:
parent
ad744735f6
commit
50a527c97d
@ -31,7 +31,7 @@ namespace glm
|
|||||||
|
|
||||||
//! Returns x raised to the y power.
|
//! Returns x raised to the y power.
|
||||||
//! From GLM_GTX_integer extension.
|
//! From GLM_GTX_integer extension.
|
||||||
GLM_FUNC_DECL int pow(int x, int y);
|
GLM_FUNC_DECL int pow(int x, uint y);
|
||||||
|
|
||||||
//! Returns the positive square root of x.
|
//! Returns the positive square root of x.
|
||||||
//! From GLM_GTX_integer extension.
|
//! From GLM_GTX_integer extension.
|
||||||
|
@ -4,10 +4,11 @@
|
|||||||
namespace glm
|
namespace glm
|
||||||
{
|
{
|
||||||
// pow
|
// pow
|
||||||
GLM_FUNC_QUALIFIER int pow(int x, int y)
|
GLM_FUNC_QUALIFIER int pow(int x, uint y)
|
||||||
{
|
{
|
||||||
if(y == 0)
|
if(y == 0)
|
||||||
return 1;
|
return x >= 0 ? 1 : -1;
|
||||||
|
|
||||||
int result = x;
|
int result = x;
|
||||||
for(int i = 1; i < y; ++i)
|
for(int i = 1; i < y; ++i)
|
||||||
result *= x;
|
result *= x;
|
||||||
@ -111,6 +112,9 @@ namespace detail
|
|||||||
|
|
||||||
GLM_FUNC_QUALIFIER uint pow(uint x, uint y)
|
GLM_FUNC_QUALIFIER uint pow(uint x, uint y)
|
||||||
{
|
{
|
||||||
|
if (y == 0)
|
||||||
|
return 1u;
|
||||||
|
|
||||||
uint result = x;
|
uint result = x;
|
||||||
for(uint i = 1; i < y; ++i)
|
for(uint i = 1; i < y; ++i)
|
||||||
result *= x;
|
result *= x;
|
||||||
|
@ -85,6 +85,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate)
|
|||||||
- Fixed references to GLM_FORCE_RADIANS which was removed #642
|
- Fixed references to GLM_FORCE_RADIANS which was removed #642
|
||||||
- Fixed glm::fastInverseSqrt to use fast inverse square #640
|
- Fixed glm::fastInverseSqrt to use fast inverse square #640
|
||||||
- Fixed axisAngle NaN #638
|
- Fixed axisAngle NaN #638
|
||||||
|
- Fixed integer pow from GTX_integer with null exponent #658
|
||||||
|
|
||||||
#### Deprecation:
|
#### Deprecation:
|
||||||
- Requires Visual Studio 2013, GCC 4.7, Clang 3.4, Cuda 7, ICC 2013 or a C++11 compiler
|
- Requires Visual Studio 2013, GCC 4.7, Clang 3.4, Cuda 7, ICC 2013 or a C++11 compiler
|
||||||
|
@ -52,6 +52,47 @@ int test_nlz()
|
|||||||
return Error;
|
return Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int test_pow_uint()
|
||||||
|
{
|
||||||
|
int Error = 0;
|
||||||
|
|
||||||
|
glm::uint const p0 = glm::pow(2u, 0u);
|
||||||
|
Error += p0 == 1u ? 0 : 1;
|
||||||
|
|
||||||
|
glm::uint const p1 = glm::pow(2u, 1u);
|
||||||
|
Error += p1 == 2u ? 0 : 1;
|
||||||
|
|
||||||
|
glm::uint const p2 = glm::pow(2u, 2u);
|
||||||
|
Error += p2 == 4u ? 0 : 1;
|
||||||
|
|
||||||
|
return Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_pow_int()
|
||||||
|
{
|
||||||
|
int Error = 0;
|
||||||
|
|
||||||
|
int const p0 = glm::pow(2, 0u);
|
||||||
|
Error += p0 == 1 ? 0 : 1;
|
||||||
|
|
||||||
|
int const p1 = glm::pow(2, 1u);
|
||||||
|
Error += p1 == 2 ? 0 : 1;
|
||||||
|
|
||||||
|
int const p2 = glm::pow(2, 2u);
|
||||||
|
Error += p2 == 4 ? 0 : 1;
|
||||||
|
|
||||||
|
int const p0n = glm::pow(-2, 0u);
|
||||||
|
Error += p0n == -1 ? 0 : 1;
|
||||||
|
|
||||||
|
int const p1n = glm::pow(-2, 1u);
|
||||||
|
Error += p1n == -2 ? 0 : 1;
|
||||||
|
|
||||||
|
int const p2n = glm::pow(-2, 2u);
|
||||||
|
Error += p2n == 4 ? 0 : 1;
|
||||||
|
|
||||||
|
return Error;
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
int Error = 0;
|
int Error = 0;
|
||||||
@ -59,6 +100,8 @@ int main()
|
|||||||
Error += test_nlz();
|
Error += test_nlz();
|
||||||
// Error += test_floor_log2();
|
// Error += test_floor_log2();
|
||||||
Error += test_log2();
|
Error += test_log2();
|
||||||
|
Error += test_pow_uint();
|
||||||
|
Error += test_pow_int();
|
||||||
|
|
||||||
return Error;
|
return Error;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user