dullboy
November 19th, 2005, 01:59 PM
Thanks for your inputs!
|
Click to See Complete Forum and Search --> : How to compute log(N!) WITHOUT using recursion? dullboy November 19th, 2005, 01:59 PM Thanks for your inputs! wildfrog November 19th, 2005, 04:42 PM Maybe this page can give you some tips: http://mathworld.wolfram.com/Factorial.html - petter Pinky98 November 19th, 2005, 04:57 PM Just use a loop... e.g. in M$ C, __int64 g = 1; for (int i=1; i<=N; i++) { g = g * i; } return log(g); Your big problem is trying to get a type large enough to contain your factorial. D_Drmmr November 20th, 2005, 12:17 PM log(n!) = log(n*(n-1)*...*2*1) = SUM(i = 1, ..., n; log(i)) So you can do this: double sum = 0.; for (int i = n; i > 0; --i) sum += log(i); Which will solve the overflow problem. bilm_ks November 24th, 2005, 07:37 AM D_Drmmr is right although you pay the cost (speed). codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |