Fix float comparaison and add float comparison warning (#1368)

GCC warns about comparison with zero, clang does not.
This commit is contained in:
Bensuperpc 2022-03-12 17:05:23 +01:00 committed by GitHub
parent 705202d22a
commit 4f77cf9e62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 1 deletions

View File

@ -181,6 +181,7 @@ else()
add_cxx_compiler_flag(-Wall) add_cxx_compiler_flag(-Wall)
add_cxx_compiler_flag(-Wextra) add_cxx_compiler_flag(-Wextra)
add_cxx_compiler_flag(-Wshadow) add_cxx_compiler_flag(-Wshadow)
add_cxx_compiler_flag(-Wfloat-equal)
if(BENCHMARK_ENABLE_WERROR) if(BENCHMARK_ENABLE_WERROR)
add_cxx_compiler_flag(-Werror RELEASE) add_cxx_compiler_flag(-Werror RELEASE)
add_cxx_compiler_flag(-Werror RELWITHDEBINFO) add_cxx_compiler_flag(-Werror RELWITHDEBINFO)

View File

@ -195,7 +195,7 @@ void State::PauseTiming() {
for (const auto& name_and_measurement : measurements) { for (const auto& name_and_measurement : measurements) {
auto name = name_and_measurement.first; auto name = name_and_measurement.first;
auto measurement = name_and_measurement.second; auto measurement = name_and_measurement.second;
BM_CHECK_EQ(counters[name], 0.0); BM_CHECK_EQ(std::fpclassify((double)counters[name]), FP_ZERO);
counters[name] = Counter(measurement, Counter::kAvgIterations); counters[name] = Counter(measurement, Counter::kAvgIterations);
} }
} }