Ramanujan's approximation to factorial

I saw this approximation for the factorial given by Ramanujan as $$\log(n!) \approx n \log n - n + \frac{\log(n(1+4n(1+2n)))}{6} + \frac{\log(\pi)}{2}$$ in wikipedia, which claims the approximation is superior to Stirling's approximation. I tried to locate the reference but unfortunately I could not.

I would appreciate if someone can throw light on how this asymptotic is obtained and the order of the error.


$$\eqalign{\log(n!) &\approx \left( \ln \left( n \right) -1 \right) n+\ln \left( \sqrt {2 \pi } \right) +\dfrac{\ln \left( n \right)}{2} +\dfrac{1}{12} n^{-1}-{\dfrac {1}{ 360}}\,{n}^{-3}+O \left( {n}^{-5} \right)\cr n\ln \left( n \right) &-n+\frac{\ln \left( n \left( 1+4\,n \left( 1+2 \,n \right) \right) \right)}{6} +\frac{\ln \left( \pi \right)}{2}\cr &= \left( \ln \left( n \right) -1 \right) n+\ln \left( \sqrt {2 \pi } \right) +\frac{ \ln \left( n \right)}{2} +\frac{1}{12}{n}^{-1}-{ \frac {1}{288}}\,{n}^{-3}+{\frac {1}{768}}\,{n}^{-4}+O \left( {n}^{-5} \right) \cr} $$

So the error in Ramanujan's approximation is asymptotic to $\left(\dfrac{1}{288} - \dfrac{1}{360}\right) n^{-3} = \dfrac{1}{1440} n^{-3}$.

EDIT: an even better approximation, then, would be

$n\ln \left( n \right) -n+\dfrac{\ln \left(1/30 + n \left( 1+4\,n \left( 1+2 \,n \right) \right) \right)}{6} +\dfrac{\ln \left( \pi \right)}{2}$

where the error is asymptotic to $-\dfrac{11}{11520} n^{-4}$. Thus at $n=10$ we have $\ln 10! \approx 15.1044125730755$, Ramanujan's approximation $\approx 15.1044119983597$ and the improved approximation $\approx 15.1044126589476$.


Well, I finally found the formula in

S. Ramanujan, The Lost Notebook and other Unpublished Papers. S. Raghavan and S. S. Rangachari, editors. Narosa, New Delhi, 1987.

page 339.