mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
[wpimath] C++: Assign zero in MakeWhiteNoiseVector if std-dev is zero (#2773)
A std-dev of zero is UB in C++. Java does not have this issue. Co-authored-by: Tyler Veness <calcmogul@gmail.com>
This commit is contained in:
committed by
GitHub
parent
9058fe803d
commit
a3e672f863
@@ -220,8 +220,14 @@ Eigen::Matrix<double, N, 1> MakeWhiteNoiseVector(
|
||||
|
||||
Eigen::Matrix<double, N, 1> result;
|
||||
for (int i = 0; i < N; ++i) {
|
||||
std::normal_distribution<> distr{0.0, stdDevs[i]};
|
||||
result(i) = distr(gen);
|
||||
// Passing a standard deviation of 0.0 to std::normal_distribution is
|
||||
// undefined behavior
|
||||
if (stdDevs[i] == 0.0) {
|
||||
result(i) = 0.0;
|
||||
} else {
|
||||
std::normal_distribution distr{0.0, stdDevs[i]};
|
||||
result(i) = distr(gen);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user