Skip to content

Commit

Permalink
Explicitly cast values of different types
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
svenihoney authored and horenmar committed Oct 14, 2024
1 parent 69d62ab commit 0b2af56
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/catch2/benchmark/detail/catch_stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ namespace Catch {
double diff = b - m;
return a + diff * diff;
} ) /
( last - first );
static_cast<double>( last - first );
return std::sqrt( variance );
}

Expand Down Expand Up @@ -213,7 +213,7 @@ namespace Catch {
double* first,
double* last ) {
auto count = last - first;
double idx = (count - 1) * k / static_cast<double>(q);
double idx = static_cast<double>((count - 1) * k) / static_cast<double>(q);
int j = static_cast<int>(idx);
double g = idx - j;
std::nth_element(first, first + j, last);
Expand Down Expand Up @@ -316,10 +316,10 @@ namespace Catch {

double accel = sum_cubes / ( 6 * std::pow( sum_squares, 1.5 ) );
long n = static_cast<long>( resample.size() );
double prob_n =
double prob_n = static_cast<double>(
std::count_if( resample.begin(),
resample.end(),
[point]( double x ) { return x < point; } ) /
[point]( double x ) { return x < point; } )) /
static_cast<double>( n );
// degenerate case with uniform samples
if ( Catch::Detail::directCompare( prob_n, 0. ) ) {
Expand Down
2 changes: 1 addition & 1 deletion src/catch2/catch_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Catch {
return static_cast<unsigned int>(getElapsedMicroseconds()/1000);
}
auto Timer::getElapsedSeconds() const -> double {
return getElapsedMicroseconds()/1000000.0;
return static_cast<double>(getElapsedMicroseconds())/1000000.0;
}


Expand Down
2 changes: 1 addition & 1 deletion src/catch2/internal/catch_random_number_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace {
SimplePcg32::result_type SimplePcg32::operator()() {
// prepare the output value
const uint32_t xorshifted = static_cast<uint32_t>(((m_state >> 18u) ^ m_state) >> 27u);
const auto output = rotate_right(xorshifted, m_state >> 59u);
const auto output = rotate_right(xorshifted, static_cast<uint32_t>(m_state >> 59u));

// advance state
m_state = m_state * 6364136223846793005ULL + s_inc;
Expand Down

0 comments on commit 0b2af56

Please sign in to comment.