Skip to content

Commit a296c40

Browse files
committed
isfinite is not available on all platforms, so add a bitmasking alternative
Compiler Explorer shows both result in the same assembly.
1 parent f896e26 commit a296c40

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

test/testautomation_audio.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515
#include <SDL3/SDL_test.h>
1616
#include "testautomation_suites.h"
1717

18+
static bool test_double_isfinite(double d)
19+
{
20+
union {
21+
Uint64 u64;
22+
double d;
23+
} d_u;
24+
d_u.d = d;
25+
return (d_u.u64 & 0x7ff0000000000000ULL) != 0x7ff0000000000000ULL;
26+
}
27+
1828
/* ================= Test Case Implementation ================== */
1929

2030
/* Fixture */
@@ -1147,11 +1157,11 @@ static int SDLCALL audio_resampleLoss(void *arg)
11471157
SDL_DestroyAudioStream(stream);
11481158
SDL_free(buf_out);
11491159
signal_to_noise = 10 * SDL_log10(sum_squared_value / sum_squared_error); /* decibel */
1150-
SDLTest_AssertCheck(ISFINITE(sum_squared_value), "Sum of squared target should be finite.");
1151-
SDLTest_AssertCheck(ISFINITE(sum_squared_error), "Sum of squared error should be finite.");
1160+
SDLTest_AssertCheck(test_double_isfinite(sum_squared_value), "Sum of squared target should be finite.");
1161+
SDLTest_AssertCheck(test_double_isfinite(sum_squared_error), "Sum of squared error should be finite.");
11521162
/* Infinity is theoretically possible when there is very little to no noise */
11531163
SDLTest_AssertCheck(!ISNAN(signal_to_noise), "Signal-to-noise ratio should not be NaN.");
1154-
SDLTest_AssertCheck(ISFINITE(max_error), "Maximum conversion error should be finite.");
1164+
SDLTest_AssertCheck(test_double_isfinite(max_error), "Maximum conversion error should be finite.");
11551165
SDLTest_AssertCheck(signal_to_noise >= spec->signal_to_noise, "Conversion signal-to-noise ratio %f dB should be no less than %f dB.",
11561166
signal_to_noise, spec->signal_to_noise);
11571167
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)
14401450
}
14411451

14421452
signal_to_noise = 10 * SDL_log10(sum_squared_value / sum_squared_error); /* decibel */
1443-
SDLTest_AssertCheck(ISFINITE(sum_squared_value), "Sum of squared target should be finite.");
1444-
SDLTest_AssertCheck(ISFINITE(sum_squared_error), "Sum of squared error should be finite.");
1453+
SDLTest_AssertCheck(test_double_isfinite(sum_squared_value), "Sum of squared target should be finite.");
1454+
SDLTest_AssertCheck(test_double_isfinite(sum_squared_error), "Sum of squared error should be finite.");
14451455
/* Infinity is theoretically possible when there is very little to no noise */
14461456
SDLTest_AssertCheck(!ISNAN(signal_to_noise), "Signal-to-noise ratio should not be NaN.");
1447-
SDLTest_AssertCheck(ISFINITE(max_error), "Maximum conversion error should be finite.");
1457+
SDLTest_AssertCheck(test_double_isfinite(max_error), "Maximum conversion error should be finite.");
14481458
SDLTest_AssertCheck(signal_to_noise >= target_signal_to_noise, "Conversion signal-to-noise ratio %f dB should be no less than %f dB.",
14491459
signal_to_noise, target_signal_to_noise);
14501460
SDLTest_AssertCheck(max_error <= target_max_error, "Maximum conversion error %f should be no more than %f.",

test/testautomation_suites.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include <SDL3/SDL_test.h>
1010

11-
#define ISFINITE(X) isfinite((float)(X))
1211
#define ISINF(X) isinf((float)(X))
1312
#define ISNAN(X) isnan((float)(X))
1413

0 commit comments

Comments
 (0)