Re: Issues with factorial operator

From: "Cui Shijun" <rancpine(at)gmail(dot)com>
To: "Dann Corbit" <DCorbit(at)connx(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Issues with factorial operator
Date: 2007-06-09 09:11:40
Message-ID: 306760850706090211r7d34f85i2f2a3e65beee86fd@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

2007/6/9, Dann Corbit <DCorbit(at)connx(dot)com>:
> #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! :-)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dann Corbit 2007-06-09 09:38:05 Re: Issues with factorial operator
Previous Message Teodor Sigaev 2007-06-09 08:01:19 Re: GiST intarray rd-tree indexes using intbig