]> git.lizzy.rs Git - minetest.git/commitdiff
Fix the part of the float test that requires IEC559/IEEE754 compliance
authorPedro Gimeno <pgimeno@users.noreply.notabug.org>
Tue, 18 Dec 2018 10:47:29 +0000 (11:47 +0100)
committerLoïc Blot <loic.blot@unix-experience.fr>
Tue, 18 Dec 2018 11:27:23 +0000 (12:27 +0100)
GCC and CLang compilers fail to support full IEC559 compliance required for the test, when certain compiler flags are active. This patch implements a heuristic that checks for the most common flag in GCC and CLang, plues an extra check which GCC disables when it's not compliant, to hopefully catch most cases where it can't run.

src/unittest/test_serialization.cpp

index b526792c42a8c88dfdd203b871f1bb152a2100d8..ca4116413ccb2fe690a5d6d45b0c301bc2c97873 100644 (file)
@@ -674,6 +674,19 @@ void TestSerialization::testFloatFormat()
                return;
        }
 
+       // The code below compares the IEEE conversion functions with a
+       // known good IEC559/IEEE754 implementation. This test neeeds
+       // IEC559 compliance in the compiler.
+#if defined(__GNUC__) && (!defined(__STDC_IEC_559__) || defined(__FAST_MATH__))
+       // GNU C++ lies about its IEC559 support when -ffast-math is active.
+       // https://gcc.gnu.org/bugzilla//show_bug.cgi?id=84949
+       bool is_iec559 = false;
+#else
+       bool is_iec559 = std::numeric_limits<f32>::is_iec559;
+#endif
+       if (!is_iec559)
+               return;
+
        auto test_single = [&fs, &fm](const u32 &i) -> bool {
                memcpy(&fm, &i, 4);
                fs = u32Tof32Slow(i);