Re: Issues with factorial operator
От | Cui Shijun |
---|---|
Тема | Re: Issues with factorial operator |
Дата | |
Msg-id | 306760850706090211r7d34f85i2f2a3e65beee86fd@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Issues with factorial operator ("Dann Corbit" <DCorbit@connx.com>) |
Ответы |
Re: Issues with factorial operator
|
Список | pgsql-hackers |
2007/6/9, Dann Corbit <DCorbit@connx.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! :-)
В списке pgsql-hackers по дате отправления: