From a296c40867b98ca8c93bcddcee6a80298c008529 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Mon, 8 Dec 2025 20:19:39 +0100
Subject: [PATCH] isfinite is not available on all platforms, so add a
bitmasking alternative
Compiler Explorer shows both result in the same assembly.
---
test/testautomation_audio.c | 22 ++++++++++++++++------
test/testautomation_suites.h | 1 -
2 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/test/testautomation_audio.c b/test/testautomation_audio.c
index 7c141b3a56181..3b1a397edd156 100644
--- a/test/testautomation_audio.c
+++ b/test/testautomation_audio.c
@@ -15,6 +15,16 @@
#include <SDL3/SDL_test.h>
#include "testautomation_suites.h"
+static bool test_double_isfinite(double d)
+{
+ union {
+ Uint64 u64;
+ double d;
+ } d_u;
+ d_u.d = d;
+ return (d_u.u64 & 0x7ff0000000000000ULL) != 0x7ff0000000000000ULL;
+}
+
/* ================= Test Case Implementation ================== */
/* Fixture */
@@ -1147,11 +1157,11 @@ static int SDLCALL audio_resampleLoss(void *arg)
SDL_DestroyAudioStream(stream);
SDL_free(buf_out);
signal_to_noise = 10 * SDL_log10(sum_squared_value / sum_squared_error); /* decibel */
- SDLTest_AssertCheck(ISFINITE(sum_squared_value), "Sum of squared target should be finite.");
- SDLTest_AssertCheck(ISFINITE(sum_squared_error), "Sum of squared error should be finite.");
+ SDLTest_AssertCheck(test_double_isfinite(sum_squared_value), "Sum of squared target should be finite.");
+ SDLTest_AssertCheck(test_double_isfinite(sum_squared_error), "Sum of squared error should be finite.");
/* Infinity is theoretically possible when there is very little to no noise */
SDLTest_AssertCheck(!ISNAN(signal_to_noise), "Signal-to-noise ratio should not be NaN.");
- SDLTest_AssertCheck(ISFINITE(max_error), "Maximum conversion error should be finite.");
+ SDLTest_AssertCheck(test_double_isfinite(max_error), "Maximum conversion error should be finite.");
SDLTest_AssertCheck(signal_to_noise >= spec->signal_to_noise, "Conversion signal-to-noise ratio %f dB should be no less than %f dB.",
signal_to_noise, spec->signal_to_noise);
SDLTest_AssertCheck(max_error <= spec->max_error, "Maximum conversion error %f should be no more than %f.",
@@ -1440,11 +1450,11 @@ static int SDLCALL audio_formatChange(void *arg)
}
signal_to_noise = 10 * SDL_log10(sum_squared_value / sum_squared_error); /* decibel */
- SDLTest_AssertCheck(ISFINITE(sum_squared_value), "Sum of squared target should be finite.");
- SDLTest_AssertCheck(ISFINITE(sum_squared_error), "Sum of squared error should be finite.");
+ SDLTest_AssertCheck(test_double_isfinite(sum_squared_value), "Sum of squared target should be finite.");
+ SDLTest_AssertCheck(test_double_isfinite(sum_squared_error), "Sum of squared error should be finite.");
/* Infinity is theoretically possible when there is very little to no noise */
SDLTest_AssertCheck(!ISNAN(signal_to_noise), "Signal-to-noise ratio should not be NaN.");
- SDLTest_AssertCheck(ISFINITE(max_error), "Maximum conversion error should be finite.");
+ SDLTest_AssertCheck(test_double_isfinite(max_error), "Maximum conversion error should be finite.");
SDLTest_AssertCheck(signal_to_noise >= target_signal_to_noise, "Conversion signal-to-noise ratio %f dB should be no less than %f dB.",
signal_to_noise, target_signal_to_noise);
SDLTest_AssertCheck(max_error <= target_max_error, "Maximum conversion error %f should be no more than %f.",
diff --git a/test/testautomation_suites.h b/test/testautomation_suites.h
index 093bb9b69f7ce..e683f79108838 100644
--- a/test/testautomation_suites.h
+++ b/test/testautomation_suites.h
@@ -8,7 +8,6 @@
#include <SDL3/SDL_test.h>
-#define ISFINITE(X) isfinite((float)(X))
#define ISINF(X) isinf((float)(X))
#define ISNAN(X) isnan((float)(X))