Note that my example is for C(n,r), but you can use the same method for your second formula. Just add up the logs of whatever you multiply in the numerator and subtract the logs of the factors of the denominator. Then the result is exp of the resulting sum.
Don On Tuesday, April 8, 2014 2:15:06 PM UTC-4, Don wrote: > > Use the fact that a*b*c*d = exp(log a + log b + log c + log d) > > double sum = 0.0; > double x; > > for(x = n-r+1.0; x <= n; x += 1.0) > sum += log(x); > > for(x = 2; x <= r; x += 1.0) > sum -= log(x); > > result = exp(sum); > > Don > > On Tuesday, April 8, 2014 2:06:47 PM UTC-4, kumar raja wrote: >> >> Hi all, >> >> I know the way to calculate value of C(n,r) using pascals identity. But i >> have a different requirement. >> >> C(n,r) = n (n-1) (n-2) ... (n-r+1) / r! >> >> Suppose the numerator is such that it cant fit into existing data type. >> >> So i remember there is a way to strike off the common factors in >> numerator and denominator then calculate the result of it. But the logic >> is not striking to me. Googled but could not find much. So please share the >> clever way to calculate the above value w/o actually computing the >> factorials and then making division. >> >> My actual requirement is to calculate the value of >> >> (n1+n2+....+nk)! / (n1!.n2!.n3!.....nk!) . >> >> >> Regards, >> Kumar Raja. >> >> >> -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
