Fixed and test round functions

This commit is contained in:
Christophe Riccio 2011-09-16 09:39:51 +01:00
parent 20816a9f94
commit 7cd97fe610
2 changed files with 70 additions and 4 deletions

View File

@ -237,6 +237,8 @@ namespace detail
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'round' only accept floating-point inputs");
if(x < 0)
return genType(int(x - genType(0.5)));
return genType(int(x + genType(0.5)));
}

View File

@ -136,23 +136,86 @@ int test_round()
Error += D == 0.0f ? 0 : 1;
float E = glm::round(0.9f);
Error += E == 1.0f ? 0 : 1;
float F = glm::round(1.9f);
float F = glm::round(1.5f);
Error += F == 2.0f ? 0 : 1;
float G = glm::round(1.9f);
Error += G == 2.0f ? 0 : 1;
}
{
float A = glm::round(-0.0f);
Error += A == 0.0f ? 0 : 1;
Error += A == 0.0f ? 0 : 1;
float B = glm::round(-0.5f);
Error += B == -1.0f ? 0 : 1;
float C = glm::round(-1.0f);
Error += C == -1.0f ? 0 : 1;
float D = glm::round(-0.1f);
Error += D == 0.0f ? 0 : 1;
Error += D == 0.0f ? 0 : 1;
float E = glm::round(-0.9f);
Error += E == -1.0f ? 0 : 1;
float F = glm::round(-1.9f);
float F = glm::round(-1.5f);
Error += F == -2.0f ? 0 : 1;
float G = glm::round(-1.9f);
Error += G == -2.0f ? 0 : 1;
}
return Error;
}
int test_roundEven()
{
int Error = 0;
{
float A = glm::roundEven(0.0f);
Error += A == 0.0f ? 0 : 1;
float B = glm::roundEven(0.5f);
Error += B == 0.0f ? 0 : 1;
float C = glm::roundEven(1.0f);
Error += C == 2.0f ? 0 : 1;
float D = glm::roundEven(0.1f);
Error += D == 0.0f ? 0 : 1;
float E = glm::roundEven(0.9f);
Error += E == 0.0f ? 0 : 1;
float F = glm::roundEven(1.9f);
Error += F == 2.0f ? 0 : 1;
float G = glm::roundEven(2.5f);
Error += G == 2.0f ? 0 : 1;
float H = glm::roundEven(2.9f);
Error += H == 2.0f ? 0 : 1;
float I = glm::roundEven(3.2f);
Error += I == 4.0f ? 0 : 1;
float J = glm::roundEven(3.5f);
Error += J == 4.0f ? 0 : 1;
float K = glm::roundEven(3.9f);
Error += K == 4.0f ? 0 : 1;
float L = glm::roundEven(4.1f);
Error += L == 4.0f ? 0 : 1;
}
{
float A = glm::roundEven(-0.0f);
Error += A == 0.0f ? 0 : 1;
float B = glm::roundEven(-0.5f);
Error += B == -2.0f ? 0 : 1;
float C = glm::roundEven(-1.0f);
Error += C == -2.0f ? 0 : 1;
float D = glm::roundEven(-0.1f);
Error += D == 0.0f ? 0 : 1;
float E = glm::roundEven(-0.9f);
Error += E == -2.0f ? 0 : 1;
float F = glm::roundEven(-1.9f);
Error += F == -2.0f ? 0 : 1;
float G = glm::roundEven(-2.5f);
Error += G == -2.0f ? 0 : 1;
float H = glm::roundEven(-2.9f);
Error += H == -2.0f ? 0 : 1;
float I = glm::roundEven(-3.2f);
Error += I == -4.0f ? 0 : 1;
float J = glm::roundEven(-3.5f);
Error += J == -4.0f ? 0 : 1;
float K = glm::roundEven(-3.9f);
Error += K == -4.0f ? 0 : 1;
}
return Error;
@ -166,6 +229,7 @@ int main()
Error += test_floatBitsToUint();
Error += test_mix();
Error += test_round();
Error += test_roundEven();
return Error;
}