I want calculate the Fisher's exact test for 2x2 table but computing factorials for large numbers causes numerical overflow! how can I use another method to calculate it?
Please have a look at our paper in Computational Statistics & Data Analysis 3 (1985) 159-185.
A. Verbeek & P.M. Kroonenberg, A survey of algorithms for exact
distributions of test statistics in r x c contingency tables with fixed margins.
It treats all kinds of algorithmic issues of calculating exact tests in contingeny tables. It also provides an extensive list of references on this particular problem.
It also deals with your questions of calculating factorials of large numbers. In particular using logarithms or the Stirling approximation.