Browse Source

isfinite is not available on all platforms, so add a bitmasking alternative

Compiler Explorer shows both result in the same assembly.
Anonymous Maarten 4 ngày trước cách đây
mục cha
commit
a296c40867
2 tập tin đã thay đổi với 16 bổ sung7 xóa
  1. 16 6
      test/testautomation_audio.c
  2. 0 1
      test/testautomation_suites.h

+ 16 - 6
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.",

+ 0 - 1
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))