From d392ce516a4d265fe62600e0bd36d506693a38a4 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Tue, 21 Mar 2023 22:03:42 +0100
Subject: [PATCH] testautomation_math: avoid equality tests with INFINITY
Fixes this warning:
warning: comparison with infinity always evaluates to false in fast floating point modes [-Wtautological-constant-compare]
---
test/testautomation_math.c | 80 +++++++++++++++++++-------------------
1 file changed, 41 insertions(+), 39 deletions(-)
diff --git a/test/testautomation_math.c b/test/testautomation_math.c
index 863ed21b5ca6..1f92a1d1e334 100644
--- a/test/testautomation_math.c
+++ b/test/testautomation_math.c
@@ -25,6 +25,8 @@
#define EULER M_E
#endif
+#define IS_INFINITY(V) fpclassify(V) == FP_INFINITE
+
/* Square root of 3 (used in atan2) */
#define SQRT3 1.7320508075688771931766041234368458390235900878906250
@@ -223,12 +225,12 @@ floor_infCases(void *args)
double result;
result = SDL_floor(INFINITY);
- SDLTest_AssertCheck(INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Floor(%f), expected %f, got %f",
INFINITY, INFINITY, result);
result = SDL_floor(-INFINITY);
- SDLTest_AssertCheck(-INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
"Floor(%f), expected %f, got %f",
-INFINITY, -INFINITY, result);
@@ -327,12 +329,12 @@ ceil_infCases(void *args)
double result;
result = SDL_ceil(INFINITY);
- SDLTest_AssertCheck(INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Ceil(%f), expected %f, got %f",
INFINITY, INFINITY, result);
result = SDL_ceil(-INFINITY);
- SDLTest_AssertCheck(-INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
"Ceil(%f), expected %f, got %f",
-INFINITY, -INFINITY, result);
@@ -431,12 +433,12 @@ trunc_infCases(void *args)
double result;
result = SDL_trunc(INFINITY);
- SDLTest_AssertCheck(INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Trunc(%f), expected %f, got %f",
INFINITY, INFINITY, result);
result = SDL_trunc(-INFINITY);
- SDLTest_AssertCheck(-INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
"Trunc(%f), expected %f, got %f",
-INFINITY, -INFINITY, result);
@@ -535,12 +537,12 @@ round_infCases(void *args)
double result;
result = SDL_round(INFINITY);
- SDLTest_AssertCheck(INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Round(%f), expected %f, got %f",
INFINITY, INFINITY, result);
result = SDL_round(-INFINITY);
- SDLTest_AssertCheck(-INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
"Round(%f), expected %f, got %f",
-INFINITY, -INFINITY, result);
@@ -639,12 +641,12 @@ fabs_infCases(void *args)
double result;
result = SDL_fabs(INFINITY);
- SDLTest_AssertCheck(INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Fabs(%f), expected %f, got %f",
INFINITY, INFINITY, result);
result = SDL_fabs(-INFINITY);
- SDLTest_AssertCheck(INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Fabs(%f), expected %f, got %f",
-INFINITY, INFINITY, result);
@@ -701,22 +703,22 @@ copysign_infCases(void *args)
double result;
result = SDL_copysign(INFINITY, -1.0);
- SDLTest_AssertCheck(-INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
"Copysign(%f,%.1f), expected %f, got %f",
INFINITY, -1.0, -INFINITY, result);
result = SDL_copysign(INFINITY, 1.0);
- SDLTest_AssertCheck(INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Copysign(%f,%.1f), expected %f, got %f",
INFINITY, 1.0, INFINITY, result);
result = SDL_copysign(-INFINITY, -1.0);
- SDLTest_AssertCheck(-INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
"Copysign(%f,%.1f), expected %f, got %f",
-INFINITY, -1.0, -INFINITY, result);
result = SDL_copysign(-INFINITY, 1.0);
- SDLTest_AssertCheck(INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Copysign(%f,%.1f), expected %f, got %f",
-INFINITY, 1.0, INFINITY, result);
@@ -1009,7 +1011,7 @@ exp_infCases(void *args)
double result;
result = SDL_exp(INFINITY);
- SDLTest_AssertCheck(INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Exp(%f), expected %f, got %f",
INFINITY, INFINITY, result);
@@ -1105,17 +1107,17 @@ log_limitCases(void *args)
double result;
result = SDL_log(INFINITY);
- SDLTest_AssertCheck(INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Log(%f), expected %f, got %f",
INFINITY, INFINITY, result);
result = SDL_log(0.0);
- SDLTest_AssertCheck(-INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
"Log(%f), expected %f, got %f",
0.0, -INFINITY, result);
result = SDL_log(-0.0);
- SDLTest_AssertCheck(-INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
"Log(%f), expected %f, got %f",
-0.0, -INFINITY, result);
@@ -1195,17 +1197,17 @@ log10_limitCases(void *args)
double result;
result = SDL_log10(INFINITY);
- SDLTest_AssertCheck(INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Log10(%f), expected %f, got %f",
INFINITY, INFINITY, result);
result = SDL_log10(0.0);
- SDLTest_AssertCheck(-INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
"Log10(%f), expected %f, got %f",
0.0, -INFINITY, result);
result = SDL_log10(-0.0);
- SDLTest_AssertCheck(-INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
"Log10(%f), expected %f, got %f",
-0.0, -INFINITY, result);
@@ -1326,12 +1328,12 @@ pow_baseZeroExpNInfCases(void *args)
double result;
result = SDL_pow(0.0, -INFINITY);
- SDLTest_AssertCheck(INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Pow(%f,%f), expected %f, got %f",
0.0, -INFINITY, INFINITY, result);
result = SDL_pow(-0.0, -INFINITY);
- SDLTest_AssertCheck(INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Pow(%f,%f), expected %f, got %f",
-0.0, -INFINITY, INFINITY, result);
@@ -1353,12 +1355,12 @@ pow_expInfCases(void *args)
0.5, INFINITY, 0.0, result);
result = SDL_pow(1.5, INFINITY);
- SDLTest_AssertCheck(INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Pow(%f,%f), expected %f, got %f",
1.5, INFINITY, INFINITY, result);
result = SDL_pow(0.5, -INFINITY);
- SDLTest_AssertCheck(INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Pow(%f,%f), expected %f, got %f",
0.5, INFINITY, INFINITY, result);
@@ -1387,7 +1389,7 @@ pow_basePInfCases(void *args)
INFINITY, -3.0, 0.0, result);
result = SDL_pow(INFINITY, 2.0);
- SDLTest_AssertCheck(INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Pow(%f,%f), expected %f, got %f",
INFINITY, 2.0, INFINITY, result);
@@ -1397,7 +1399,7 @@ pow_basePInfCases(void *args)
INFINITY, -2.12345, 0.0, result);
result = SDL_pow(INFINITY, 3.1345);
- SDLTest_AssertCheck(INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Pow(%f,%f), expected %f, got %f",
INFINITY, 3.12345, INFINITY, result);
@@ -1433,17 +1435,17 @@ pow_baseNInfCases(void *args)
-INFINITY, -5.5, 0.0, result);
result = SDL_pow(-INFINITY, 3.0);
- SDLTest_AssertCheck(-INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
"Pow(%f,%f), expected %f, got %f",
-INFINITY, 3.0, -INFINITY, result);
result = SDL_pow(-INFINITY, 2.0);
- SDLTest_AssertCheck(INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Pow(%f,%f), expected %f, got %f",
-INFINITY, 2.0, INFINITY, result);
result = SDL_pow(-INFINITY, 5.5);
- SDLTest_AssertCheck(INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Pow(%f,%f), expected %f, got %f",
-INFINITY, 5.5, INFINITY, result);
@@ -1545,7 +1547,7 @@ pow_baseNZeroExpOddCases(void *args)
double result;
result = SDL_pow(-0.0, -3.0);
- SDLTest_AssertCheck(-INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
"Pow(%f,%f), expected %f, got %f",
-0.0, -3.0, -INFINITY, result);
@@ -1569,7 +1571,7 @@ pow_basePZeroExpOddCases(void *args)
double result;
result = SDL_pow(0.0, -5.0);
- SDLTest_AssertCheck(INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Pow(%f,%f), expected %f, got %f",
0.0, -5.0, INFINITY, result);
@@ -1595,12 +1597,12 @@ pow_baseNZeroCases(void *args)
double result;
result = SDL_pow(-0.0, -3.5);
- SDLTest_AssertCheck(INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Pow(%f,%f), expected %f, got %f",
-0.0, -3.5, INFINITY, result);
result = SDL_pow(-0.0, -4.0);
- SDLTest_AssertCheck(INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Pow(%f,%f), expected %f, got %f",
-0.0, -4.0, INFINITY, result);
@@ -1631,12 +1633,12 @@ pow_basePZeroCases(void *args)
double result;
result = SDL_pow(0.0, -3.5);
- SDLTest_AssertCheck(INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Pow(%f,%f), expected %f, got %f",
0.0, -3.5, INFINITY, result);
result = SDL_pow(0.0, -4.0);
- SDLTest_AssertCheck(INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Pow(%f,%f), expected %f, got %f",
0.0, -4.0, INFINITY, result);
@@ -1744,7 +1746,7 @@ static int
sqrt_infCase(void *args)
{
const double result = SDL_sqrt(INFINITY);
- SDLTest_AssertCheck(INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Sqrt(%f), expected %f, got %f",
INFINITY, INFINITY, result);
return TEST_COMPLETED;
@@ -1837,12 +1839,12 @@ scalbn_infCases(void *args)
double result;
result = SDL_scalbn(INFINITY, 1);
- SDLTest_AssertCheck(INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result > 0,
"Scalbn(%f,%d), expected %f, got %f",
INFINITY, 1, INFINITY, result);
result = SDL_scalbn(-INFINITY, 1);
- SDLTest_AssertCheck(-INFINITY == result,
+ SDLTest_AssertCheck(IS_INFINITY(result) && result < 0,
"Scalbn(%f,%d), expected %f, got %f",
-INFINITY, 1, -INFINITY, result);