- Fixed integer pow from GTX_integer with null exponent #658

This commit is contained in:
Christophe Riccio
2017-07-24 11:39:16 +02:00
parent ad744735f6
commit 50a527c97d
4 changed files with 51 additions and 3 deletions

View File

@@ -31,7 +31,7 @@ namespace glm
//! Returns x raised to the y power.
//! 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.
//! From GLM_GTX_integer extension.

View File

@@ -4,10 +4,11 @@
namespace glm
{
// pow
GLM_FUNC_QUALIFIER int pow(int x, int y)
GLM_FUNC_QUALIFIER int pow(int x, uint y)
{
if(y == 0)
return 1;
return x >= 0 ? 1 : -1;
int result = x;
for(int i = 1; i < y; ++i)
result *= x;
@@ -111,6 +112,9 @@ namespace detail
GLM_FUNC_QUALIFIER uint pow(uint x, uint y)
{
if (y == 0)
return 1u;
uint result = x;
for(uint i = 1; i < y; ++i)
result *= x;