35 QL_REQUIRE(!x.empty(),
"interpolationIndices(x," << v <<
"): empty x");
37 return std::make_tuple(0, 0, 1.0);
38 if (v < x.front() || QuantLib::close_enough(v, x.front()))
39 return std::make_tuple(0, 0, 1.0);
40 if (v > x.back() || QuantLib::close_enough(v, x.back()))
41 return std::make_tuple(x.size() - 1, x.size() - 1, 1.0);
42 Size index = std::distance(x.begin(), std::upper_bound(x.begin(), x.end(), v, [](Real x1, Real x2) {
43 return x1 < x2 && !QuantLib::close_enough(x1, x2);
45 return std::make_tuple(index - 1, index, (x[index] - v) / (x[index] - x[index - 1]));
std::tuple< Size, Size, Real > interpolationIndices(const T &x, const Real v)