Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2/benchmark
diff options
context:
space:
mode:
authorMartin Hořeňovský2022-05-14 15:37:39 +0200
committerMartin Hořeňovský2022-05-14 15:47:20 +0200
commitfc3d11b1d1090a5bcbcc9e410a460f9bf6a1f474 (patch)
tree226e86969f762eb65eb41877413f9578c79c1cfe /src/catch2/benchmark
parent1ef65d60f182059297cb07498ca211884a868c48 (diff)
downloadcatch3-fc3d11b1d1090a5bcbcc9e410a460f9bf6a1f474.tar.gz
Add Wfloat-equal to default-enabled warnings
This is kinda messy, because there is no good way to signal to the compiler that some code uses direct comparison of floating point numbers intentionally, so instead we have to use diagnostic pragmas. We also have to over-suppress the test files, because Clang (and possibly GCC) still issue warnings from template instantiation even if the instantion site is under warning suppression, so the template definition has to be under warning suppression as well. Closes #2406
Diffstat (limited to 'src/catch2/benchmark')
-rw-r--r--src/catch2/benchmark/detail/catch_stats.cpp13
-rw-r--r--src/catch2/benchmark/detail/catch_stats.hpp8
2 files changed, 19 insertions, 2 deletions
diff --git a/src/catch2/benchmark/detail/catch_stats.cpp b/src/catch2/benchmark/detail/catch_stats.cpp
index 10511d4c..02350806 100644
--- a/src/catch2/benchmark/detail/catch_stats.cpp
+++ b/src/catch2/benchmark/detail/catch_stats.cpp
@@ -137,6 +137,15 @@ namespace Catch {
namespace Benchmark {
namespace Detail {
+#if defined( __GNUC__ ) || defined( __clang__ )
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wfloat-equal"
+#endif
+ bool directCompare( double lhs, double rhs ) { return lhs == rhs; }
+#if defined( __GNUC__ ) || defined( __clang__ )
+# pragma GCC diagnostic pop
+#endif
+
double weighted_average_quantile(int k, int q, std::vector<double>::iterator first, std::vector<double>::iterator last) {
auto count = last - first;
double idx = (count - 1) * k / static_cast<double>(q);
@@ -144,7 +153,9 @@ namespace Catch {
double g = idx - j;
std::nth_element(first, first + j, last);
auto xj = first[j];
- if (g == 0) return xj;
+ if ( directCompare( g, 0 ) ) {
+ return xj;
+ }
auto xj1 = *std::min_element(first + (j + 1), last);
return xj + g * (xj1 - xj);
diff --git a/src/catch2/benchmark/detail/catch_stats.hpp b/src/catch2/benchmark/detail/catch_stats.hpp
index 998616e1..db93fa29 100644
--- a/src/catch2/benchmark/detail/catch_stats.hpp
+++ b/src/catch2/benchmark/detail/catch_stats.hpp
@@ -24,6 +24,10 @@ namespace Catch {
namespace Detail {
using sample = std::vector<double>;
+ // Used when we know we want == comparison of two doubles
+ // to centralize warning suppression
+ bool directCompare( double lhs, double rhs );
+
double weighted_average_quantile(int k, int q, std::vector<double>::iterator first, std::vector<double>::iterator last);
template <typename Iterator>
@@ -103,7 +107,9 @@ namespace Catch {
long n = static_cast<long>(resample.size());
double prob_n = std::count_if(resample.begin(), resample.end(), [point](double x) { return x < point; }) / static_cast<double>(n);
// degenerate case with uniform samples
- if (prob_n == 0) return { point, point, point, confidence_level };
+ if ( directCompare( prob_n, 0. ) ) {
+ return { point, point, point, confidence_level };
+ }
double bias = normal_quantile(prob_n);
double z1 = normal_quantile((1. - confidence_level) / 2.);