2007/6/9, Dann Corbit <[EMAIL PROTECTED]>:
#include <math.h>

double          log10nfactorialestimate(unsigned n)
{
    unsigned        i;
    double          estimate = 0;
    for (i = 1; i < n; i++)
        estimate += log10(n);
    return estimate;
}

#ifdef UNIT_TEST
#include <stdio.h>
#include <time.h>
int             main(void)
{
    clock_t         start,
                    end;
    double          answer;
    start = clock();
    end = clock();
    answer = log10nfactorialestimate(92838278);
    printf("log 10 of 92838278! is pretty close to %g and took %g
seconds\n",
           answer, (end - start) / (1.0 * CLOCKS_PER_SEC));
    return 0;
}
#endif
/*
C:\tmp>cl /W4 /Ox /DUNIT_TEST log10EST.C
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42
for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

log10EST.C
Microsoft (R) Incremental Linker Version 8.00.50727.42
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:log10EST.exe
log10EST.obj

C:\tmp>log10est
log 10 of 92838278! is pretty close to 7.3971e+008 and took 0 seconds
*/

Hum... I think there is a little improvement: when n is too large,(say
n>10, 000) we can use Stirling's formula to get the estimated value of
n!    :-)

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

              http://archives.postgresql.org

Reply via email to