add floating point comparison warnings

This commit is contained in:
Eric Fiselier 2015-03-12 20:27:29 -04:00
parent f022d780eb
commit 66bf7c8f71
5 changed files with 18 additions and 12 deletions

View File

@ -39,6 +39,7 @@ add_cxx_compiler_flag(-Wshadow)
add_cxx_compiler_flag(-Werror) add_cxx_compiler_flag(-Werror)
add_cxx_compiler_flag(-pedantic-errors) add_cxx_compiler_flag(-pedantic-errors)
add_cxx_compiler_flag(-Wshorten-64-to-32) add_cxx_compiler_flag(-Wshorten-64-to-32)
add_cxx_compiler_flag(-Wfloat-equal)
# TODO(ericwf): enable this for g++ # TODO(ericwf): enable this for g++
#add_cxx_compiler_flag(-Wzero-as-null-pointer-constant) #add_cxx_compiler_flag(-Wzero-as-null-pointer-constant)
# Release flags # Release flags

View File

@ -665,11 +665,11 @@ void RunBenchmark(const benchmark::internal::Benchmark::Instance& b,
(seconds >= FLAGS_benchmark_min_time) || (seconds >= FLAGS_benchmark_min_time) ||
(real_accumulated_time >= 5*FLAGS_benchmark_min_time)) { (real_accumulated_time >= 5*FLAGS_benchmark_min_time)) {
double bytes_per_second = 0; double bytes_per_second = 0;
if (total.bytes_processed > 0 && seconds != 0.0) { if (total.bytes_processed > 0 && seconds > 0.0) {
bytes_per_second = (total.bytes_processed / seconds); bytes_per_second = (total.bytes_processed / seconds);
} }
double items_per_second = 0; double items_per_second = 0;
if (total.items_processed > 0 && seconds != 0.0) { if (total.items_processed > 0 && seconds > 0.0) {
items_per_second = (total.items_processed / seconds); items_per_second = (total.items_processed / seconds);
} }

View File

@ -2,8 +2,10 @@
#define BENCHMARK_STAT_H_ #define BENCHMARK_STAT_H_
#include <cmath> #include <cmath>
#include <ostream>
#include <limits> #include <limits>
#include <ostream>
#include <type_traits>
namespace benchmark { namespace benchmark {
@ -13,10 +15,10 @@ class Stat1;
template <typename VType, typename NumType> template <typename VType, typename NumType>
class Stat1MinMax; class Stat1MinMax;
typedef Stat1<float, float> Stat1_f; typedef Stat1<float, int64_t> Stat1_f;
typedef Stat1<double, double> Stat1_d; typedef Stat1<double, int64_t> Stat1_d;
typedef Stat1MinMax<float, float> Stat1MinMax_f; typedef Stat1MinMax<float, int64_t> Stat1MinMax_f;
typedef Stat1MinMax<double, double> Stat1MinMax_d; typedef Stat1MinMax<double, int64_t> Stat1MinMax_d;
template <typename VType> template <typename VType>
class Vector2; class Vector2;
@ -133,6 +135,9 @@ class Stat1 {
} }
private: private:
static_assert(std::is_integral<NumType>::value &&
!std::is_same<NumType, bool>::value,
"NumType must be an integral type that is not bool.");
// Let i be the index of the samples provided (using +=) // Let i be the index of the samples provided (using +=)
// and weight[i],value[i] be the data of sample #i // and weight[i],value[i] be the data of sample #i
// then the variables have the following meaning: // then the variables have the following meaning:

View File

@ -158,7 +158,7 @@ static void BM_LongTest(benchmark::State& state) {
while (state.KeepRunning()) while (state.KeepRunning())
for (int i = 0; i < state.range_x(); ++i) for (int i = 0; i < state.range_x(); ++i)
tracker += i; tracker += i;
assert(tracker != 0.0); assert(tracker > 1.0);
} }
BENCHMARK(BM_LongTest)->Range(1<<16,1<<28); BENCHMARK(BM_LongTest)->Range(1<<16,1<<28);

View File

@ -1,8 +1,8 @@
#include "benchmark/benchmark.h" #include "benchmark/benchmark.h"
#include <assert.h> #include <cassert>
#include <math.h> #include <cmath>
#include <stdint.h> #include <cstdint>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
@ -69,7 +69,7 @@ BENCHMARK(BM_CalculatePi)->ThreadPerCpu();
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
benchmark::Initialize(&argc, argv); benchmark::Initialize(&argc, argv);
assert(CalculatePi(1) == 0.0); assert(std::fabs(CalculatePi(1)) < 0.001);
TestReporter test_reporter; TestReporter test_reporter;
benchmark::RunSpecifiedBenchmarks(&test_reporter); benchmark::RunSpecifiedBenchmarks(&test_reporter);