From 6bf7dc9ca6f460188f49a5cf5fe87d99c8f345ed Mon Sep 17 00:00:00 2001 From: Sven Fischer Date: Thu, 23 May 2024 16:49:57 +0200 Subject: [PATCH] Explicitly cast values of different types In case the warning -Werror=conversion is active with GCC, the warnings about "conversion from A to B may change value" lead to a compilation error. This explicitly convert the values to address these warnings. --- src/catch2/benchmark/detail/catch_stats.cpp | 8 ++++---- src/catch2/catch_timer.cpp | 2 +- src/catch2/internal/catch_random_number_generator.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/catch2/benchmark/detail/catch_stats.cpp b/src/catch2/benchmark/detail/catch_stats.cpp index e6de359c44..2a5a2e038e 100644 --- a/src/catch2/benchmark/detail/catch_stats.cpp +++ b/src/catch2/benchmark/detail/catch_stats.cpp @@ -178,7 +178,7 @@ namespace Catch { double diff = b - m; return a + diff * diff; } ) / - ( last - first ); + static_cast( last - first ); return std::sqrt( variance ); } @@ -213,7 +213,7 @@ namespace Catch { double* first, double* last ) { auto count = last - first; - double idx = (count - 1) * k / static_cast(q); + double idx = static_cast((count - 1) * k) / static_cast(q); int j = static_cast(idx); double g = idx - j; std::nth_element(first, first + j, last); @@ -316,10 +316,10 @@ namespace Catch { double accel = sum_cubes / ( 6 * std::pow( sum_squares, 1.5 ) ); long n = static_cast( resample.size() ); - double prob_n = + double prob_n = static_cast( std::count_if( resample.begin(), resample.end(), - [point]( double x ) { return x < point; } ) / + [point]( double x ) { return x < point; } )) / static_cast( n ); // degenerate case with uniform samples if ( Catch::Detail::directCompare( prob_n, 0. ) ) { diff --git a/src/catch2/catch_timer.cpp b/src/catch2/catch_timer.cpp index d75ea70c8b..0b768c8560 100644 --- a/src/catch2/catch_timer.cpp +++ b/src/catch2/catch_timer.cpp @@ -30,7 +30,7 @@ namespace Catch { return static_cast(getElapsedMicroseconds()/1000); } auto Timer::getElapsedSeconds() const -> double { - return getElapsedMicroseconds()/1000000.0; + return static_cast(getElapsedMicroseconds())/1000000.0; } diff --git a/src/catch2/internal/catch_random_number_generator.cpp b/src/catch2/internal/catch_random_number_generator.cpp index 6a79dff39a..c88cd8f2d1 100644 --- a/src/catch2/internal/catch_random_number_generator.cpp +++ b/src/catch2/internal/catch_random_number_generator.cpp @@ -52,7 +52,7 @@ namespace { SimplePcg32::result_type SimplePcg32::operator()() { // prepare the output value const uint32_t xorshifted = static_cast(((m_state >> 18u) ^ m_state) >> 27u); - const auto output = rotate_right(xorshifted, m_state >> 59u); + const auto output = rotate_right(xorshifted, static_cast(m_state >> 59u)); // advance state m_state = m_state * 6364136223846793005ULL + s_inc;