/*************************************************** * Program to demonstrate LN(X!) Function * * ------------------------------------------------ * * Reference: BASIC Scientific Subroutines, Vol. II * * By F.R. Ruckdeschel, BYTE/McGRAWW-HILL, 1981 [1].* * * * C++ Version by J.-P. Moreau, Paris. * * ------------------------------------------------ * * SAMPLE RUN: * * * * X LN(X!) EXP(LN(X!)) * * ---------------------------------- * * 1 -0.000307 1 * * 2 0.693146 2 * * 3 1.791759 6 * * 4 3.178054 24 * * 5 4.787492 120 * * 6 6.579251 720 * * 7 8.525161 5040 * * 8 10.604603 40320 * * 9 12.801827 362880 * * 10 15.104413 3628800 * * 11 17.502308 39916800 * * 12 19.987214 479001600 * * 13 22.552164 6227020800 * * 14 25.191221 87178291200 * * 15 27.899271 1307674368000 * * * **************************************************** See file chi-sq.txt, equation (2.3.9) */ #include #include int i; double x,y; /************************************************** * Series approximation subroutine for LN(X!) * * Accuracy better then 6 places for x>=3 * * Accuracy better than 12 places for x>10 * * Advantage is that very large values of the * * argument can be used without fear of over flow. * * Reference: CRC Math Tables. * * x is the input, y is the output. * **************************************************/ void LN_FactX() { double x1; x1 = 1.0 / (x * x); y = (x + 0.5) * log(x) - x * (1 - x1 / 12 + x1 * x1 / 360 - x1 * x1 * x1 / 1260 + x1 * x1 * x1 * x1 / 1680); y += 0.918938533205; } void main() { printf("\n X LN(X!) EXP(LN(X!))\n"); printf("---------------------------------\n"); for (i = 1; i<16; i++) { x = (double) i; LN_FactX(); printf(" %2d %9.6f %13.0f\n",i,y,exp(y)); } printf("---------------------------------\n\n"); } // End of file Logn!.cpp