mirror of
https://github.com/g-truc/glm.git
synced 2025-04-13 16:50:38 +00:00
Fixed floatBitXint tests
This commit is contained in:
parent
6628d62ce6
commit
d2e1718286
1 changed files with 65 additions and 10 deletions
|
@ -16,31 +16,85 @@ int test_floatBitsToInt()
|
|||
{
|
||||
float A = 1.0f;
|
||||
int B = glm::floatBitsToInt(A);
|
||||
Error += B == *(float*)&A ? 0 : 1;
|
||||
float C = glm::intBitsToFloat(B);
|
||||
int D = *(int*)&A;
|
||||
Error += B == D ? 0 : 1;
|
||||
Error += A == C ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec2 A(1.0f, 2.0f);
|
||||
glm::ivec2 B = glm::floatBitsToInt(A);
|
||||
Error += B.x == *(float*)&(A.x) ? 0 : 1;
|
||||
Error += B.y == *(float*)&(A.y) ? 0 : 1;
|
||||
glm::vec2 C = glm::intBitsToFloat(B);
|
||||
Error += B.x == *(int*)&(A.x) ? 0 : 1;
|
||||
Error += B.y == *(int*)&(A.y) ? 0 : 1;
|
||||
Error += A == C? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec3 A(1.0f, 2.0f, 3.0f);
|
||||
glm::ivec3 B = glm::floatBitsToInt(A);
|
||||
Error += B.x == *(float*)&(A.x) ? 0 : 1;
|
||||
Error += B.y == *(float*)&(A.y) ? 0 : 1;
|
||||
Error += B.z == *(float*)&(A.z) ? 0 : 1;
|
||||
glm::vec3 C = glm::intBitsToFloat(B);
|
||||
Error += B.x == *(int*)&(A.x) ? 0 : 1;
|
||||
Error += B.y == *(int*)&(A.y) ? 0 : 1;
|
||||
Error += B.z == *(int*)&(A.z) ? 0 : 1;
|
||||
Error += A == C? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::ivec4 B = glm::floatBitsToInt(A);
|
||||
Error += B.x == *(float*)&(A.x) ? 0 : 1;
|
||||
Error += B.y == *(float*)&(A.y) ? 0 : 1;
|
||||
Error += B.z == *(float*)&(A.z) ? 0 : 1;
|
||||
Error += B.w == *(float*)&(A.w) ? 0 : 1;
|
||||
glm::vec4 C = glm::intBitsToFloat(B);
|
||||
Error += B.x == *(int*)&(A.x) ? 0 : 1;
|
||||
Error += B.y == *(int*)&(A.y) ? 0 : 1;
|
||||
Error += B.z == *(int*)&(A.z) ? 0 : 1;
|
||||
Error += B.w == *(int*)&(A.w) ? 0 : 1;
|
||||
Error += A == C? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_floatBitsToUint()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
float A = 1.0f;
|
||||
glm::uint B = glm::floatBitsToUint(A);
|
||||
float C = glm::intBitsToFloat(B);
|
||||
Error += B == *(glm::uint*)&A ? 0 : 1;
|
||||
Error += A == C? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec2 A(1.0f, 2.0f);
|
||||
glm::uvec2 B = glm::floatBitsToUint(A);
|
||||
glm::vec2 C = glm::uintBitsToFloat(B);
|
||||
Error += B.x == *(glm::uint*)&(A.x) ? 0 : 1;
|
||||
Error += B.y == *(glm::uint*)&(A.y) ? 0 : 1;
|
||||
Error += A == C ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec3 A(1.0f, 2.0f, 3.0f);
|
||||
glm::uvec3 B = glm::floatBitsToUint(A);
|
||||
glm::vec3 C = glm::uintBitsToFloat(B);
|
||||
Error += B.x == *(glm::uint*)&(A.x) ? 0 : 1;
|
||||
Error += B.y == *(glm::uint*)&(A.y) ? 0 : 1;
|
||||
Error += B.z == *(glm::uint*)&(A.z) ? 0 : 1;
|
||||
Error += A == C? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::uvec4 B = glm::floatBitsToUint(A);
|
||||
glm::vec4 C = glm::uintBitsToFloat(B);
|
||||
Error += B.x == *(glm::uint*)&(A.x) ? 0 : 1;
|
||||
Error += B.y == *(glm::uint*)&(A.y) ? 0 : 1;
|
||||
Error += B.z == *(glm::uint*)&(A.z) ? 0 : 1;
|
||||
Error += B.w == *(glm::uint*)&(A.w) ? 0 : 1;
|
||||
Error += A == C? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
|
@ -72,6 +126,7 @@ int main()
|
|||
int Error = 0;
|
||||
|
||||
Error += test_floatBitsToInt();
|
||||
Error += test_floatBitsToUint();
|
||||
Error += test_mix();
|
||||
|
||||
return Error;
|
||||
|
|
Loading…
Add table
Reference in a new issue