Skip to content

Commit c30e3c9

Browse files
Akos299tdavidcl
authored andcommitted
[Clang-tidy] fix warning for Tscal used as loop counter (Shamrock-code#1424)
warning: Variable 'x' with floating point type 'Tscal' should not be used as a loop counter [clang-analyzer-security.FloatLoopCounter] 85 | for (Tscal x = 0; x < Ker::Rkern; x += step) {...}; Replaced the foor loop by a while loop. Co-authored-by: David--Cléris Timothée <timothee.davidcleris@proton.me>
1 parent 72c6793 commit c30e3c9

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/tests/shammath/sphkernelsTests.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "shamtest/PyScriptHandle.hpp"
2020
#include "shamtest/details/TestResult.hpp"
2121
#include "shamtest/shamtest.hpp"
22+
#include <cmath>
2223
#include <vector>
2324

2425
template<class Ker>
@@ -82,13 +83,17 @@ inline void validate_kernel_3d(
8283
// is df = f' ?
8384
Tscal L2_sum = 0;
8485
Tscal step = 0.01;
85-
for (Tscal x = 0; x < Ker::Rkern; x += step) {
86-
Tscal diff = Ker::df(x) - shammath::derivative_upwind<Tscal>(x, dx, [](Tscal x) {
86+
87+
const int num_steps = static_cast<int>(std::ceil(Ker::Rkern / step));
88+
for (int i = 0; i < num_steps; i++) {
89+
const Tscal x = i * step;
90+
Tscal diff = Ker::df(x) - shammath::derivative_upwind<Tscal>(x, dx, [](Tscal x) {
8791
return Ker::f(x);
8892
});
8993
diff *= gen_norm3d;
9094
L2_sum += diff * diff * step;
9195
}
96+
9297
REQUIRE_FLOAT_EQUAL(L2_sum, 0, tol);
9398
}
9499

0 commit comments

Comments
 (0)