commit 0f77a020e2d9205a35ab06d3f0cbf3193281e6a0
parent 2779e45e6db1d2666472181a88ec1f8f5fbef14d
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Fri, 27 Oct 2017 16:32:15 +0200
Fix a libstdc++ non conformity and some gcc warnings.
Diffstat:
3 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -128,6 +128,7 @@ if(NOT NO_TEST)
${SSP_SOURCE_DIR}/${_name}.c
${SSP_SOURCE_DIR}/${_name}.h
${SSP_SOURCE_DIR}/test_ssp_utils.h)
+ set_source_files_properties(${SSP_SOURCE_DIR}/${_name}.c PROPERTIES LANGUAGE C++)
target_link_libraries(${_name} ssp RSys ${MATH_LIB})
set(_libraries ${ARGN})
foreach(_lib ${_libraries})
diff --git a/src/ssp_ranst_piecewise_linear.c b/src/ssp_ranst_piecewise_linear.c
@@ -299,12 +299,16 @@ ssp_ranst_piecewise_linear_float_pdf
return 0;
const auto& inter = ran->distrib->intervals();
+ /* std::piecewise_linear_distribution<float>::densities()
+ * should be a std::vector<float>, but is a std::vector<double> with gcc
+ * => use explicit casts */
const auto& dens = ran->distrib->densities();
auto b = std::lower_bound(inter.begin(), inter.end(), x);
size_t idx = b - inter.begin();
- if (x == *b) return dens[idx];
+ if (x == *b) return (float)dens[idx];
idx--;
ASSERT(idx < inter.size() - 1);
- return (dens[idx+1] * (x - inter[idx]) + dens[idx] * (inter[idx+1] - x))
- / (inter[idx+1] - inter[idx]);
+ return
+ ((float)dens[idx+1] * (x-inter[idx]) + (float)dens[idx] * (inter[idx+1]-x))
+ / (inter[idx+1] - inter[idx]);
}
\ No newline at end of file
diff --git a/src/test_ssp_ran_uniform_disk.h b/src/test_ssp_ran_uniform_disk.h
@@ -106,8 +106,8 @@ TEST()
CHECK(R3_EQ_EPS(tmp, pt2, (REAL)1.e-6), 1);
ASSERT(pt[2] == 0);
/* locate pt in a 10x10 grid */
- r = (unsigned)((100 + pt[0]) / 20);
- c = (unsigned)((100 + pt[1]) / 20);
+ r = (int)((100 + pt[0]) / 20);
+ c = (int)((100 + pt[1]) / 20);
++counts[r][c];
}
@@ -115,17 +115,17 @@ TEST()
int x = (r >= 5 ? r - 4 : r - 5) * 20;
for(c = 0; c < 10; c++) {
int y = (c >= 5 ? c - 4 : c - 5) * 20;
- unsigned r2 = x * x + y * y;
+ int r2 = x * x + y * y;
if(r2 > 100 * 100)
/* this square is not (fully) in the disk */
continue;
++nb;
- x_sum += counts[r][c];
- x2_sum += counts[r][c] * counts[r][c];
+ x_sum += (REAL)counts[r][c];
+ x2_sum += (REAL)(counts[r][c] * counts[r][c]);
}
}
- mean = x_sum / nb;
- std = x2_sum / nb - mean*mean;
+ mean = x_sum / (REAL)nb;
+ std = x2_sum / (REAL)nb - mean*mean;
std = std > 0 ? SQRT(std) : 0;
printf("%g %g\n", mean, std);
CHECK(fabs(mean - exp_mean) < 10, 1);