I'm trying to write tests to validate inverse of matrix, but test fails when I use FLT_EPSILON to compare results.
Comparing function looks like this: test_assert_mat4_eq
What I'm trying to do is:
A = random matrix (4x4 float matrix)
B = inv(A)
C = inv(B)
assert(A == C) <---- fails
First let me explain how I calculate matrix inverse; mat4 is 4x4 float matrix, if SIMD is enabled then inverse of matrix will be computed via SIMD instructions (SSE2 and AVX).
You can see matrix inverse code at glm_mat4_inv if SSE2 is enabled then the inverse is calculated via glm_mat4_inv_sse2 also there is glm_mat4_inv_precise_sse2 version to get more precision by avoid _mm_rcp_ps instruction. I used the second (glm_mat4_inv_precise_sse2) version to test.
assert_true(fabsf(m1[i][j] - m2[i][j]) <= 0.0001);
passes on my macbook but it still fails on linux.
assert_true(fabsf(m1[i][j] - m2[i][j]) <= FLT_EPSILON);
this even not passes on macos. Maybe comparing with 0.001 will also work on linux but precision is too low.
I also created an issue on glm repo (https://github.com/g-truc/glm/issues/700) because this issue also valid for glm.
What is wrong with this? Why the precision is too low? Is this ok? Should I leave it like this (by removing the test or by changing precision)?
NOTE: Random matrix is generating with test_rand_mat4 function. But I'm using it just for generating a matrix. I'm not using any random matrix in anywhere, all matrices are affine transformation matrices, maybe I should use affine transforms (which is the main purpose) for comparing