We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e8ddbfd commit 64ea348Copy full SHA for 64ea348
1 file changed
exputil/ExpDeproj.cc
@@ -58,7 +58,17 @@ double ExpDeproj::mass(double R)
58
if (R > rmax) return mv.back();
59
60
auto it = std::lower_bound(rv.begin(), rv.end(), R);
61
- int idx = std::distance(rv.begin(), it);
+ // If R is slightly larger than the largest grid point due to rounding,
62
+ // lower_bound may return rv.end(); in that case, use the last mass value.
63
+ if (it == rv.end()) {
64
+ return mv.back();
65
+ }
66
+
67
+ std::size_t idx = static_cast<std::size_t>(std::distance(rv.begin(), it));
68
+ if (idx >= rv.size()) {
69
+ // Defensive guard; should not happen after the it == rv.end() check.
70
71
72
if (rv[idx] == R) {
73
return mv[idx];
74
} else {
0 commit comments