This routine computes the dilogarithm for a real argument. In Lewin’s notation this is \(\operatorname{Li}_2(x)\), the real part of the dilogarithm of a real \(x\). It is defined by the integral representation \(\operatorname{Li}_2(x) = -\operatorname{Re}\int_0^x (\log(1-s) / s) ds\). Note that \(\operatorname{Im}(\operatorname{Li}_2(x)) = 0\) for \(x <= 1\), and \(-\pi\log(x)\) for \(x > 1\).

Note that Abramowitz & Stegun refer to the Spence integral \(S(x)=\operatorname{Li}_2(1-x)\) as the dilogarithm rather than \(\operatorname{Li}_2(x)\).