Skip to content

Commit 0b2af56

Browse files
svenihoneyhorenmar
authored andcommitted
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.
1 parent 69d62ab commit 0b2af56

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/catch2/benchmark/detail/catch_stats.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ namespace Catch {
178178
double diff = b - m;
179179
return a + diff * diff;
180180
} ) /
181-
( last - first );
181+
static_cast<double>( last - first );
182182
return std::sqrt( variance );
183183
}
184184

@@ -213,7 +213,7 @@ namespace Catch {
213213
double* first,
214214
double* last ) {
215215
auto count = last - first;
216-
double idx = (count - 1) * k / static_cast<double>(q);
216+
double idx = static_cast<double>((count - 1) * k) / static_cast<double>(q);
217217
int j = static_cast<int>(idx);
218218
double g = idx - j;
219219
std::nth_element(first, first + j, last);
@@ -316,10 +316,10 @@ namespace Catch {
316316

317317
double accel = sum_cubes / ( 6 * std::pow( sum_squares, 1.5 ) );
318318
long n = static_cast<long>( resample.size() );
319-
double prob_n =
319+
double prob_n = static_cast<double>(
320320
std::count_if( resample.begin(),
321321
resample.end(),
322-
[point]( double x ) { return x < point; } ) /
322+
[point]( double x ) { return x < point; } )) /
323323
static_cast<double>( n );
324324
// degenerate case with uniform samples
325325
if ( Catch::Detail::directCompare( prob_n, 0. ) ) {

src/catch2/catch_timer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace Catch {
3030
return static_cast<unsigned int>(getElapsedMicroseconds()/1000);
3131
}
3232
auto Timer::getElapsedSeconds() const -> double {
33-
return getElapsedMicroseconds()/1000000.0;
33+
return static_cast<double>(getElapsedMicroseconds())/1000000.0;
3434
}
3535

3636

src/catch2/internal/catch_random_number_generator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ namespace {
5252
SimplePcg32::result_type SimplePcg32::operator()() {
5353
// prepare the output value
5454
const uint32_t xorshifted = static_cast<uint32_t>(((m_state >> 18u) ^ m_state) >> 27u);
55-
const auto output = rotate_right(xorshifted, m_state >> 59u);
55+
const auto output = rotate_right(xorshifted, static_cast<uint32_t>(m_state >> 59u));
5656

5757
// advance state
5858
m_state = m_state * 6364136223846793005ULL + s_inc;

0 commit comments

Comments
 (0)