Maybe. However, even with type double
, overflow is reached at N==170.
Another problem with double
is that the result is
only an approximation to the exact value.
double
s have the equivalent of about 15 decimal digits
of accuracy. This might not be good enough.
For example, if you are doing number theory or cryptography,
approximations are useless.
Often math formulas use factorial, but explicit calculation of factorial can
be avoided by rearranging the operations of the formula.
Avoid explicit calculation of factorial.
For example, the number of arrangements that can be made of r
objects selected from n
objects is:
n! / (n-r)!
Say that you want to select 5 objects out of 30. It looks like you need to calculate both 30! and 25! both of which would be disasters. But using cancellation, the formula becomes:
30 * 29 * 28 * 27 * 26
which can be calculated without problems. This is one of the programming exercises.
If you drop a brick from a tower, what happens?