Skip to content

Commit

Permalink
CMake: print the bit representation of the test number
Browse files Browse the repository at this point in the history
I need this to investigate why the test is failing in Travis CI.
  • Loading branch information
jyrkive committed Dec 22, 2016
1 parent 5fc50bf commit 1553cc6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Expand Up @@ -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()
Expand Down
10 changes: 9 additions & 1 deletion src/compile_time_tests/ieee_754.cpp
@@ -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.
Expand All @@ -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;
}

0 comments on commit 1553cc6

Please sign in to comment.