Task: Calculate the factorial of a large number. In P, the factorial can only be calculated up to 170.
> factorial(170)
[1] 7.257416e+306
For large numbers, overflow occurs:
> factorial(171)
[1] Inf
Warning message:
In factorial(171) : value out of range in 'gammafn'
Use factorialZ
from the gmp
package:
> gmp::factorialZ(171)
Big Integer ('bigz') :
[1] 1241018070217667823424840524103103992616605577501693185388951803611996075221691752992751978120487585576464959501670387052809889858690710767331242032218484364310473577889968548278290754541561964852153468318044293239598173696899657235903947616152278558180061176365108428800000000000000000000000000000000000000000