mirror of
https://github.com/g-truc/glm.git
synced 2024-11-26 02:04:35 +00:00
Improved exponential funtion test coverage
This commit is contained in:
parent
cedc72e07a
commit
01bac6a524
@ -79,6 +79,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate)
|
||||
- Reduced warnings when using very strict compilation flags #646
|
||||
- length() member functions are constexpr #657
|
||||
- Added support of -Weverything with Clang #646
|
||||
- Improved exponential funtion test coverage
|
||||
|
||||
#### Fixes:
|
||||
- Removed doxygen references to GTC_half_float which was removed in 0.9.4
|
||||
|
@ -27,15 +27,47 @@ static int test_pow()
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_sqrt()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
float A = glm::sqrt(4.f);
|
||||
Error += glm::epsilonEqual(A, 2.f, 0.01f) ? 0 : 1;
|
||||
|
||||
glm::vec1 B = glm::sqrt(glm::vec1(4.f));
|
||||
Error += glm::all(glm::epsilonEqual(B, glm::vec1(2.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec2 C = glm::sqrt(glm::vec2(4.f));
|
||||
Error += glm::all(glm::epsilonEqual(C, glm::vec2(2.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec3 D = glm::sqrt(glm::vec3(4.f));
|
||||
Error += glm::all(glm::epsilonEqual(D, glm::vec3(2.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec4 E = glm::sqrt(glm::vec4(4.f));
|
||||
Error += glm::all(glm::epsilonEqual(E, glm::vec4(2.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
|
||||
static int test_exp()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
float A = glm::exp(10.f);
|
||||
glm::vec1 B = glm::exp(glm::vec1(10.f));
|
||||
glm::vec2 C = glm::exp(glm::vec2(10.f));
|
||||
glm::vec3 D = glm::exp(glm::vec3(10.f));
|
||||
glm::vec4 E = glm::exp(glm::vec4(10.f));
|
||||
float A = glm::exp(1.f);
|
||||
Error += glm::epsilonEqual(A, glm::e<float>(), 0.01f) ? 0 : 1;
|
||||
|
||||
glm::vec1 B = glm::exp(glm::vec1(1.f));
|
||||
Error += glm::all(glm::epsilonEqual(B, glm::vec1(glm::e<float>()), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec2 C = glm::exp(glm::vec2(1.f));
|
||||
Error += glm::all(glm::epsilonEqual(C, glm::vec2(glm::e<float>()), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec3 D = glm::exp(glm::vec3(1.f));
|
||||
Error += glm::all(glm::epsilonEqual(D, glm::vec3(glm::e<float>()), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec4 E = glm::exp(glm::vec4(1.f));
|
||||
Error += glm::all(glm::epsilonEqual(E, glm::vec4(glm::e<float>()), 0.01f)) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
@ -66,11 +98,20 @@ static int test_exp2()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
float A = glm::exp2(10.f);
|
||||
glm::vec1 B = glm::exp2(glm::vec1(10.f));
|
||||
glm::vec2 C = glm::exp2(glm::vec2(10.f));
|
||||
glm::vec3 D = glm::exp2(glm::vec3(10.f));
|
||||
glm::vec4 E = glm::exp2(glm::vec4(10.f));
|
||||
float A = glm::exp2(4.f);
|
||||
Error += glm::epsilonEqual(A, 16.f, 0.01f) ? 0 : 1;
|
||||
|
||||
glm::vec1 B = glm::exp2(glm::vec1(16.f));
|
||||
Error += glm::all(glm::epsilonEqual(B, glm::vec1(4.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec2 C = glm::exp2(glm::vec2(16.f, 8.f));
|
||||
Error += glm::all(glm::epsilonEqual(C, glm::vec2(4.f, 3.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec3 D = glm::exp2(glm::vec3(16.f, 8.f, 4.f));
|
||||
Error += glm::all(glm::epsilonEqual(D, glm::vec3(4.f, 3.f, 2.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec4 E = glm::exp2(glm::vec4(16.f, 8.f, 4.f, 2.f));
|
||||
Error += glm::all(glm::epsilonEqual(E, glm::vec4(4.f, 3.f, 2.f, 1.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
@ -79,34 +120,20 @@ static int test_log2()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
float A = glm::log2(10.f);
|
||||
glm::vec1 B = glm::log2(glm::vec1(10.f));
|
||||
glm::vec2 C = glm::log2(glm::vec2(10.f));
|
||||
glm::vec3 D = glm::log2(glm::vec3(10.f));
|
||||
glm::vec4 E = glm::log2(glm::vec4(10.f));
|
||||
float A = glm::log2(16.f);
|
||||
Error += glm::epsilonEqual(A, 1.f, 0.01f) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
glm::vec1 B = glm::log2(glm::vec1(16.f));
|
||||
Error += glm::all(glm::epsilonEqual(B, glm::vec1(4.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
static int test_sqrt()
|
||||
{
|
||||
int Error = 0;
|
||||
glm::vec2 C = glm::log2(glm::vec2(16.f, 8.f));
|
||||
Error += glm::all(glm::epsilonEqual(C, glm::vec2(4.f, 3.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
# if GLM_ARCH & GLM_ARCH_SSE2_BIT
|
||||
for(float f = 0.1f; f < 30.0f; f += 0.1f)
|
||||
{
|
||||
float r = _mm_cvtss_f32(_mm_sqrt_ps(_mm_set1_ps(f)));
|
||||
float s = std::sqrt(f);
|
||||
Error += glm::abs(r - s) < 0.01f ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
# endif//GLM_ARCH & GLM_ARCH_SSE2_BIT
|
||||
glm::vec3 D = glm::log2(glm::vec3(16.f, 8.f, 4.f));
|
||||
Error += glm::all(glm::epsilonEqual(D, glm::vec3(4.f, 3.f, 2.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
float A = glm::sqrt(10.f);
|
||||
glm::vec1 B = glm::sqrt(glm::vec1(10.f));
|
||||
glm::vec2 C = glm::sqrt(glm::vec2(10.f));
|
||||
glm::vec3 D = glm::sqrt(glm::vec3(10.f));
|
||||
glm::vec4 E = glm::sqrt(glm::vec4(10.f));
|
||||
glm::vec4 E = glm::log2(glm::vec4(16.f, 8.f, 4.f, 2.f));
|
||||
Error += glm::all(glm::epsilonEqual(E, glm::vec4(4.f, 3.f, 2.f, 1.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
@ -115,19 +142,20 @@ static int test_inversesqrt()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::uint ulp(0);
|
||||
float diff(0.0f);
|
||||
float A = glm::inversesqrt(16.f) * glm::sqrt(16.f);
|
||||
Error += glm::epsilonEqual(A, 1.f, 0.01f) ? 0 : 1;
|
||||
|
||||
for(float f = 0.001f; f < 10.f; f *= 1.01f)
|
||||
{
|
||||
glm::lowp_fvec1 u(f);
|
||||
glm::lowp_fvec1 lowp_v = glm::inversesqrt(u);
|
||||
float defaultp_v = glm::inversesqrt(f);
|
||||
glm::vec1 B = glm::inversesqrt(glm::vec1(16.f)) * glm::sqrt(16.f);;
|
||||
Error += glm::all(glm::epsilonEqual(B, glm::vec1(1.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
ulp = glm::max(glm::float_distance(lowp_v.x, defaultp_v), ulp);
|
||||
diff = glm::abs(lowp_v.x - defaultp_v);
|
||||
Error += diff > 0.1f ? 1 : 0;
|
||||
}
|
||||
glm::vec2 C = glm::inversesqrt(glm::vec2(16.f)) * glm::sqrt(16.f);;
|
||||
Error += glm::all(glm::epsilonEqual(C, glm::vec2(1.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec3 D = glm::inversesqrt(glm::vec3(16.f)) * glm::sqrt(16.f);;
|
||||
Error += glm::all(glm::epsilonEqual(D, glm::vec3(1.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec4 E = glm::inversesqrt(glm::vec4(16.f, 8.f, 4.f, 2.f)) * glm::sqrt(16.f);
|
||||
Error += glm::all(glm::epsilonEqual(E, glm::vec4(1.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
@ -137,12 +165,12 @@ int main()
|
||||
int Error = 0;
|
||||
|
||||
Error += test_pow();
|
||||
Error += test_sqrt();
|
||||
Error += test_exp();
|
||||
Error += test_log();
|
||||
Error += test_exp2();
|
||||
Error += test_log2();
|
||||
//Error += test_sqrt();
|
||||
//Error += test_inversesqrt();
|
||||
Error += test_inversesqrt();
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user