The Lanczos algorithm for matrix tridiagonalisation suffers from strong numerical instability in finite precision arithmetic when applied to evaluate matrix eigenvalues. The mechanism by which this instability arises is well documented in the literature. A recent application of the Lanczos algorithm proposed by Bai, Fahey and Golub allows quadrature evaluation of inner products of the form $\psi^\dagger\cdot g(\mtx{A})\cdot\psi$. We show that this quadrature evaluation is numerically stable (accurate to machine precision) and explain how the numerical errors which are such a fundamental element of the finite precision Lanczos tridiagonalisation procedure are automatically and exactly compensated in the Bai, Fahey and Golub algorithm. In the process, we shed new light on the mechanism by which roundoff error corrupts the Lanczos procedure.