OverflowError: long int too large to convert to float in python

Factorials get large real fast: >>> math.factorial(170) 7257415615307998967396728211129263114716991681296451376543577798900561843401706157852350749242617459511490991237838520776666022565442753025328900773207510902400430280058295603966612599658257104398558294257568966313439612262571094946806711205568880457193340212661452800000000000000000000000000000000000000000L Note the L; the factorial of 170 is still convertable to a float: >>> float(math.factorial(170)) 7.257415615307999e+306 but the next factorial is too large: >>> float(math.factorial(171)) Traceback (most recent call last): File “<stdin>”, line 1, in <module> OverflowError: long int too large to convert to float You could … Read more

What is the fastest factorial function in JavaScript? [closed]

You can search for (1…100)! on Wolfram|Alpha to pre-calculate the factorial sequence. The first 100 numbers are: 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 87178291200, 1307674368000, 20922789888000, 355687428096000, 6402373705728000, 121645100408832000, 2432902008176640000, 51090942171709440000, 1124000727777607680000, 25852016738884976640000, 620448401733239439360000, 15511210043330985984000000, 403291461126605635584000000, 10888869450418352160768000000, 304888344611713860501504000000, 8841761993739701954543616000000, 265252859812191058636308480000000, 8222838654177922817725562880000000, 263130836933693530167218012160000000, 8683317618811886495518194401280000000, 295232799039604140847618609643520000000, 10333147966386144929666651337523200000000, 371993326789901217467999448150835200000000, 13763753091226345046315979581580902400000000, 523022617466601111760007224100074291200000000, … Read more

Fast exact bigint factorial

I have a solution: (4N!)=((2N!)^2) . mul(i=all primes<=4N) of [i^sum(j=1,2,3,4,5,…4N>=i^j) of [(4N/(i^j))%2]] sub-terms of T2 are always prime^exponent where exponent can be computed on small integers like this: for (e=0,j=N4;j;e+=j&1,j/=p); where e is exponent, p is prime and N4 is 4*N Code for the new equation: // edit beg: // Sorry, forget to copy sorted … Read more