Skip to content

Commit 64ea348

Browse files
The9CatCopilot
andauthored
Update exputil/ExpDeproj.cc
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent e8ddbfd commit 64ea348

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

exputil/ExpDeproj.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,17 @@ double ExpDeproj::mass(double R)
5858
if (R > rmax) return mv.back();
5959

6060
auto it = std::lower_bound(rv.begin(), rv.end(), R);
61-
int idx = std::distance(rv.begin(), it);
61+
// 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+
return mv.back();
71+
}
6272
if (rv[idx] == R) {
6373
return mv[idx];
6474
} else {

0 commit comments

Comments
 (0)