add floating point comparison warnings
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b4a36bd..947239b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -39,6 +39,7 @@
add_cxx_compiler_flag(-Werror)
add_cxx_compiler_flag(-pedantic-errors)
add_cxx_compiler_flag(-Wshorten-64-to-32)
+add_cxx_compiler_flag(-Wfloat-equal)
# TODO(ericwf): enable this for g++
#add_cxx_compiler_flag(-Wzero-as-null-pointer-constant)
# Release flags
diff --git a/src/benchmark.cc b/src/benchmark.cc
index 8b0682e..78eda59 100644
--- a/src/benchmark.cc
+++ b/src/benchmark.cc
@@ -665,11 +665,11 @@
(seconds >= FLAGS_benchmark_min_time) ||
(real_accumulated_time >= 5*FLAGS_benchmark_min_time)) {
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);
}
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);
}
diff --git a/src/stat.h b/src/stat.h
index 435743c..c4ecfe8 100644
--- a/src/stat.h
+++ b/src/stat.h
@@ -2,8 +2,10 @@
#define BENCHMARK_STAT_H_
#include <cmath>
-#include <ostream>
#include <limits>
+#include <ostream>
+#include <type_traits>
+
namespace benchmark {
@@ -13,10 +15,10 @@
template <typename VType, typename NumType>
class Stat1MinMax;
-typedef Stat1<float, float> Stat1_f;
-typedef Stat1<double, double> Stat1_d;
-typedef Stat1MinMax<float, float> Stat1MinMax_f;
-typedef Stat1MinMax<double, double> Stat1MinMax_d;
+typedef Stat1<float, int64_t> Stat1_f;
+typedef Stat1<double, int64_t> Stat1_d;
+typedef Stat1MinMax<float, int64_t> Stat1MinMax_f;
+typedef Stat1MinMax<double, int64_t> Stat1MinMax_d;
template <typename VType>
class Vector2;
@@ -133,6 +135,9 @@
}
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 +=)
// and weight[i],value[i] be the data of sample #i
// then the variables have the following meaning:
diff --git a/test/benchmark_test.cc b/test/benchmark_test.cc
index d44ea31..dd009af 100644
--- a/test/benchmark_test.cc
+++ b/test/benchmark_test.cc
@@ -158,7 +158,7 @@
while (state.KeepRunning())
for (int i = 0; i < state.range_x(); ++i)
tracker += i;
- assert(tracker != 0.0);
+ assert(tracker > 1.0);
}
BENCHMARK(BM_LongTest)->Range(1<<16,1<<28);
diff --git a/test/filter_test.cc b/test/filter_test.cc
index 00c2955..c7258ac 100644
--- a/test/filter_test.cc
+++ b/test/filter_test.cc
@@ -1,8 +1,8 @@
#include "benchmark/benchmark.h"
-#include <assert.h>
-#include <math.h>
-#include <stdint.h>
+#include <cassert>
+#include <cmath>
+#include <cstdint>
#include <iostream>
#include <sstream>
@@ -69,7 +69,7 @@
int main(int argc, const char* argv[]) {
benchmark::Initialize(&argc, argv);
- assert(CalculatePi(1) == 0.0);
+ assert(std::fabs(CalculatePi(1)) < 0.001);
TestReporter test_reporter;
benchmark::RunSpecifiedBenchmarks(&test_reporter);