largest factorial that can be computed

L

Loane Sharp

Hi there

I am using the following function to calculate the factorial of a number
(53! = 53x52x51x...x1). I have three questions for you (assume I have
practically unlimited available memory):

(a) what is the largest factorial that I can compute using the most
economical datatypes?
(b) does the number in (a) differ if I reframe the computation, say, in
terms of logs?
(c) what is the largest array of 0/1 values that I can declare?

Please help!

Best regards
Loane


Public x As Long
Public facNumber As Integer
Public arrPossibilities() As Byte

[...]

Public Function Factorial(ByVal facNumber As Integer) As Long
If facNumber <= 1 Then
Factorial = 1
Else
Factorial = facNumber * Factorial(facNumber - 1)
End If
End Function 'Factorial
 
G

Guest

You can calculate very large factorials with limited accuracy.

Be careful.

Excel integer math only handles 15 digits. After around 17! you will reach
that limit.
 
G

Guest

Loane said:
Hi there

I am using the following function to calculate the factorial of a number
(53! = 53x52x51x...x1). I have three questions for you (assume I have
practically unlimited available memory):

(a) what is the largest factorial that I can compute using the most
economical datatypes?
(b) does the number in (a) differ if I reframe the computation, say, in
terms of logs?
(c) what is the largest array of 0/1 values that I can declare?

Please help!

Best regards
Loane


Public x As Long
Public facNumber As Integer
Public arrPossibilities() As Byte

[...]

Public Function Factorial(ByVal facNumber As Integer) As Long
If facNumber <= 1 Then
Factorial = 1
Else
Factorial = facNumber * Factorial(facNumber - 1)
End If
End Function 'Factorial
----------------------------------

If you mean by using Excel's built in functions as in your code (multiply for
example) then it only carries a limited number of digits -- 14 or 15. As an
example, start computing your factorials, and check each one by dividing back to
see if you get the previous factorial. When you don't anymore, then you've hit
the limits of Excel's built in functions.

On the other hand if you have a penchant for doing this problem in Excel VBA
which belongs in some other more speedy programming language, you can manually
create your own million+ bit long integer (using arrays of shorter integers) and
write your own multiply and convert to decimal routines, and you can sit around
waiting eons (literally) for execution, then you can compute just about any
factorial you want.

But why would one want to? Time is more of a limitation than anything given
enough programming effort. Given a million years or so you could compute a heck
of a big factorial.

Good luck...

Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top