GaussJacobiPolynomial::beta throws 'can't compute b_k' for constructor-valid parameters
Summary
GaussJacobiPolynomial::beta(k) throws can't compute b_k for jacobi integration for constructor-valid parameters near the α = -1 boundary, although the true recurrence coefficient is finite (order 1e-10 scale). The close_enough band introduced by PR #166 and the later close_enough modernization both miss this state.
Repro (compiled against current master e429e9f1):
#include <ql/math/integrals/gaussianorthogonalpolynomial.hpp>
#include <iostream>
int main() {
QuantLib::GaussJacobiPolynomial p(-0.9999999998999999, -1e-10);
try {
std::cout << p.beta(1) << "\n";
} catch (std::exception& e) {
std::cout << "THROWS: " << e.what() << "\n"; // <- this fires
}
}
Both parameters satisfy the constructor's own validity constraint (alpha, beta > -1).
Mechanism
For k = 1 the beta recurrence has denominator s*s*(s*s - 1) with s = 2k + alpha + beta. Here the true value of s is 1 + 1e-17, which rounds to exactly 1.0 in double precision, so the computed denominator is exactly 0.0. The close_enough(denom, 0.0) guard fires, and the numerator is tiny but not zero (about 4.8e-26), so the code takes the !close_enough(num, 0.0) arm and throws, without ever reaching the l'Hospital branch that exists precisely for this case.
The close_enough(num, 0.0) test compares against zero in the absolute sense (it only passes when num is exactly 0.0), so any rounding noise in the numerator defeats it. This is the same defect PR #166 fixed for a nearby parameter band; the fix's band and the modernized comparison still leave a gap for α within one ulp-scale of -1.
Suggested fix
Either use a relative band for the numerator test (close_enough(num, 0.0) against a scale derived from the parameter magnitudes), or restructure so the l'Hospital branch is taken whenever the denominator is degenerate, with its own denominator guarded as it already is.
Environment
QuantLib master e429e9f1, compiled locally (Boost 1.92, g++ 16, C++17). The failure is parameter-driven, so it is version-independent back to the #166-era code.
Found by a formal-verification audit of historical QuantLib PRs (blind re-derivation of PR #166's fix on pre-merge code); AI-assisted (ZCode/GLM-5.3-flash).