test: Accept small numerical differences in more mathematical tests

We can't rely on irrational numbers like pi being represented exactly,
particularly when compiling for i386, where the i387 floating-point
interface carries out calculations in registers that have higher
precision than the actual double-precision variable. The 1980s were a
strange time.

Resolves: https://github.com/libsdl-org/SDL/issues/8311
Signed-off-by: Simon McVittie <smcv@collabora.com>
(cherry picked from commit 6248472c0c738496a6f246aafa07a0e30afa6a01)
This commit is contained in:
Simon McVittie 2023-09-28 16:29:15 +01:00 committed by Sam Lantinga
parent d1c5038f16
commit 69f3bb2e34

View file

@ -2256,7 +2256,7 @@ acos_limitCases(void *args)
1.0, 0.0, result); 1.0, 0.0, result);
result = SDL_acos(-1.0); result = SDL_acos(-1.0);
SDLTest_AssertCheck(M_PI == result, SDLTest_AssertCheck(SDL_fabs(M_PI - result) <= EPSILON,
"Acos(%f), expected %f, got %f", "Acos(%f), expected %f, got %f",
-1.0, M_PI, result); -1.0, M_PI, result);
@ -2343,12 +2343,12 @@ asin_limitCases(void *args)
double result; double result;
result = SDL_asin(1.0); result = SDL_asin(1.0);
SDLTest_AssertCheck(M_PI / 2.0 == result, SDLTest_AssertCheck(SDL_fabs(M_PI / 2.0 - result) <= EPSILON,
"Asin(%f), expected %f, got %f", "Asin(%f), expected %f, got %f",
1.0, M_PI / 2.0, result); 1.0, M_PI / 2.0, result);
result = SDL_asin(-1.0); result = SDL_asin(-1.0);
SDLTest_AssertCheck(-M_PI / 2.0 == result, SDLTest_AssertCheck(SDL_fabs(-M_PI / 2.0 - result) <= EPSILON,
"Asin(%f), expected %f, got %f", "Asin(%f), expected %f, got %f",
-1.0, -M_PI / 2.0, result); -1.0, -M_PI / 2.0, result);
@ -2535,7 +2535,7 @@ atan2_bothZeroCases(void *args)
{ 0.0, -0.0, M_PI }, { 0.0, -0.0, M_PI },
{ -0.0, -0.0, -M_PI }, { -0.0, -0.0, -M_PI },
}; };
return helper_ddtod("SDL_atan2", SDL_atan2, cases, SDL_arraysize(cases)); return helper_ddtod_inexact("SDL_atan2", SDL_atan2, cases, SDL_arraysize(cases));
} }
/** /**
@ -2554,7 +2554,7 @@ atan2_yZeroCases(void *args)
{ -0.0, 1.0, -0.0 }, { -0.0, 1.0, -0.0 },
{ -0.0, -1.0, -M_PI } { -0.0, -1.0, -M_PI }
}; };
return helper_ddtod("SDL_atan2", SDL_atan2, cases, SDL_arraysize(cases)); return helper_ddtod_inexact("SDL_atan2", SDL_atan2, cases, SDL_arraysize(cases));
} }
/** /**
@ -2570,7 +2570,7 @@ atan2_xZeroCases(void *args)
{ 1.0, -0.0, M_PI / 2.0 }, { 1.0, -0.0, M_PI / 2.0 },
{ -1.0, -0.0, -M_PI / 2.0 } { -1.0, -0.0, -M_PI / 2.0 }
}; };
return helper_ddtod("SDL_atan2", SDL_atan2, cases, SDL_arraysize(cases)); return helper_ddtod_inexact("SDL_atan2", SDL_atan2, cases, SDL_arraysize(cases));
} }
/* Infinity cases */ /* Infinity cases */
@ -2589,22 +2589,22 @@ atan2_bothInfCases(void *args)
double result; double result;
result = SDL_atan2(INFINITY, INFINITY); result = SDL_atan2(INFINITY, INFINITY);
SDLTest_AssertCheck(M_PI / 4.0 == result, SDLTest_AssertCheck(SDL_fabs(M_PI / 4.0 - result) <= EPSILON,
"Atan2(%f,%f), expected %f, got %f", "Atan2(%f,%f), expected %f, got %f",
INFINITY, INFINITY, M_PI / 4.0, result); INFINITY, INFINITY, M_PI / 4.0, result);
result = SDL_atan2(INFINITY, -INFINITY); result = SDL_atan2(INFINITY, -INFINITY);
SDLTest_AssertCheck(3.0 * M_PI / 4.0 == result, SDLTest_AssertCheck(SDL_fabs(3.0 * M_PI / 4.0 - result) <= EPSILON,
"Atan2(%f,%f), expected %f, got %f", "Atan2(%f,%f), expected %f, got %f",
INFINITY, -INFINITY, 3.0 * M_PI / 4.0, result); INFINITY, -INFINITY, 3.0 * M_PI / 4.0, result);
result = SDL_atan2(-INFINITY, INFINITY); result = SDL_atan2(-INFINITY, INFINITY);
SDLTest_AssertCheck(-M_PI / 4.0 == result, SDLTest_AssertCheck(SDL_fabs(-M_PI / 4.0 - result) <= EPSILON,
"Atan2(%f,%f), expected %f, got %f", "Atan2(%f,%f), expected %f, got %f",
-INFINITY, INFINITY, -M_PI / 4.0, result); -INFINITY, INFINITY, -M_PI / 4.0, result);
result = SDL_atan2(-INFINITY, -INFINITY); result = SDL_atan2(-INFINITY, -INFINITY);
SDLTest_AssertCheck(-3.0 * M_PI / 4.0 == result, SDLTest_AssertCheck(SDL_fabs(-3.0 * M_PI / 4.0 - result) <= EPSILON,
"Atan2(%f,%f), expected %f, got %f", "Atan2(%f,%f), expected %f, got %f",
-INFINITY, -INFINITY, -3.0 * M_PI / 4.0, result); -INFINITY, -INFINITY, -3.0 * M_PI / 4.0, result);
@ -2621,22 +2621,22 @@ atan2_yInfCases(void *args)
double result; double result;
result = SDL_atan2(INFINITY, 1.0); result = SDL_atan2(INFINITY, 1.0);
SDLTest_AssertCheck(M_PI / 2.0 == result, SDLTest_AssertCheck(SDL_fabs(M_PI / 2.0 - result) <= EPSILON,
"Atan2(%f,%f), expected %f, got %f", "Atan2(%f,%f), expected %f, got %f",
INFINITY, 1.0, M_PI / 2.0, result); INFINITY, 1.0, M_PI / 2.0, result);
result = SDL_atan2(INFINITY, -1.0); result = SDL_atan2(INFINITY, -1.0);
SDLTest_AssertCheck(M_PI / 2.0 == result, SDLTest_AssertCheck(SDL_fabs(M_PI / 2.0 - result) <= EPSILON,
"Atan2(%f,%f), expected %f, got %f", "Atan2(%f,%f), expected %f, got %f",
INFINITY, -1.0, M_PI / 2.0, result); INFINITY, -1.0, M_PI / 2.0, result);
result = SDL_atan2(-INFINITY, 1.0); result = SDL_atan2(-INFINITY, 1.0);
SDLTest_AssertCheck(-M_PI / 2.0 == result, SDLTest_AssertCheck(SDL_fabs(-M_PI / 2.0 - result) <= EPSILON,
"Atan2(%f,%f), expected %f, got %f", "Atan2(%f,%f), expected %f, got %f",
-INFINITY, 1.0, -M_PI / 2.0, result); -INFINITY, 1.0, -M_PI / 2.0, result);
result = SDL_atan2(-INFINITY, -1.0); result = SDL_atan2(-INFINITY, -1.0);
SDLTest_AssertCheck(-M_PI / 2.0 == result, SDLTest_AssertCheck(SDL_fabs(-M_PI / 2.0 - result) <= EPSILON,
"Atan2(%f,%f), expected %f, got %f", "Atan2(%f,%f), expected %f, got %f",
-INFINITY, -1.0, -M_PI / 2.0, result); -INFINITY, -1.0, -M_PI / 2.0, result);
@ -2665,12 +2665,12 @@ atan2_xInfCases(void *args)
-1.0, INFINITY, -0.0, result); -1.0, INFINITY, -0.0, result);
result = SDL_atan2(1.0, -INFINITY); result = SDL_atan2(1.0, -INFINITY);
SDLTest_AssertCheck(M_PI == result, SDLTest_AssertCheck(SDL_fabs(M_PI - result) <= EPSILON,
"Atan2(%f,%f), expected %f, got %f", "Atan2(%f,%f), expected %f, got %f",
1.0, -INFINITY, M_PI, result); 1.0, -INFINITY, M_PI, result);
result = SDL_atan2(-1.0, -INFINITY); result = SDL_atan2(-1.0, -INFINITY);
SDLTest_AssertCheck(-M_PI == result, SDLTest_AssertCheck(SDL_fabs(-M_PI - result) <= EPSILON,
"Atan2(%f,%f), expected %f, got %f", "Atan2(%f,%f), expected %f, got %f",
-1.0, -INFINITY, -M_PI, result); -1.0, -INFINITY, -M_PI, result);