Skip to content

Commit 8e4095f

Browse files
Pedro Gimenonerzhul
Pedro Gimeno
authored andcommittedDec 18, 2018
Fix the part of the float test that requires IEC559/IEEE754 compliance
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.
1 parent 7a4d4bc commit 8e4095f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
 

Diff for: ‎src/unittest/test_serialization.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,19 @@ void TestSerialization::testFloatFormat()
674674
return;
675675
}
676676

677+
// The code below compares the IEEE conversion functions with a
678+
// known good IEC559/IEEE754 implementation. This test neeeds
679+
// IEC559 compliance in the compiler.
680+
#if defined(__GNUC__) && (!defined(__STDC_IEC_559__) || defined(__FAST_MATH__))
681+
// GNU C++ lies about its IEC559 support when -ffast-math is active.
682+
// https://gcc.gnu.org/bugzilla//show_bug.cgi?id=84949
683+
bool is_iec559 = false;
684+
#else
685+
bool is_iec559 = std::numeric_limits<f32>::is_iec559;
686+
#endif
687+
if (!is_iec559)
688+
return;
689+
677690
auto test_single = [&fs, &fm](const u32 &i) -> bool {
678691
memcpy(&fm, &i, 4);
679692
fs = u32Tof32Slow(i);

0 commit comments

Comments
 (0)
Please sign in to comment.