CMake: print the bit representation of the test number

I need this to investigate why the test is failing in Travis CI.
This commit is contained in:
Jyrki Vesterinen 2016-12-22 22:54:05 +02:00
parent 5fc50bf9ae
commit 1553cc6b6b
2 changed files with 12 additions and 2 deletions

View file

@ -56,8 +56,10 @@ option(ENABLE_LIBPNG "Enable support for writing png files (screenshots, images)
option(ENABLE_HISTORY "Enable using GNU history for history in lua console" ON)
if(NOT CMAKE_CROSSCOMPILING)
try_run(IEEE754_TEST_RETURN_CODE IEEE754_TEST_COMPILED ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/src/compile_time_tests/ieee_754.cpp)
try_run(IEEE754_TEST_RETURN_CODE IEEE754_TEST_COMPILED ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/src/compile_time_tests/ieee_754.cpp
RUN_OUTPUT_VARIABLE IEEE754_TEST_OUTPUT)
if(NOT IEEE754_TEST_RETURN_CODE EQUAL 0)
message(${IEEE754_TEST_OUTPUT})
message(FATAL_ERROR "Your platform does not represent floating point numbers in the IEEE 754 format.")
endif()
else()

View file

@ -1,4 +1,6 @@
#include <cinttypes>
#include <cstdint>
#include <cstdio>
// This test verifies that floating point numbers are represented in the IEEE 754 format.
// Wesnoth requires that.
@ -11,7 +13,13 @@ int main()
} number;
number.floating_point_number = 1.2;
bool match = (number.integer == 0x3FF3333333333333ull);
if (!match)
{
std::printf("Wrong binary representation. Expected 0x3FF3333333333333, got 0x%" PRIX64 "\n",
number.integer);
}
// Return code zero means success.
// Thus, check that the bit representation is *not* what IEEE 754 specifies.
return number.integer != 0x3FF3333333333333ull;
return !match;
}