VB icon

Quick N! (Factorial) calculation using Double!

Email
Submitted on: 1/27/2015 10:57:00 PM
By: michele berardi (from psc cd)  
Level: Advanced
User Rating: By 3 Users
Compatibility: VB 3.0, VB 4.0 (16-bit), VB 4.0 (32-bit), VB 5.0, VB 6.0, VB Script, ASP (Active Server Pages) , VBA MS Access, VBA MS Excel
Views: 1142
 
     Explain a metodology for a quick computation of N! ( factorial) suggestion and optimization are wellcomed!
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Quick N! (Factorial) calculation using Double!
' Description:Explain a metodology for a quick computation of
N! ( factorial) suggestion and optimization are wellcomed!
' By: michele berardi (from psc cd)
'**************************************

Dim N As Double, b As Double, c As Double, p As Double
'
' Fast Way To Calculate N! ( N Factorial)
'
' A is N
' using visual basic my original algorithm
' is adapted to the vb limits..
' you can use long or int instead of double
' for small calculation..
' some tips require the use of asr (aritmetic
' shift right)
' instead of division by 2!
' and code optimization instead - 1 you can....
' a good exercize of optimization... enjoy!
' (also assembly form of this code boost the
' performances!)
'
' N.B.
' using double I extend the range of N!
' that i can represent!
' PASS TO VARIABLE N 
' THE VALUE FOR WITCH
' YOU MUST CALCULATE
' FACTORIAL ( N! )
' 
c = N - 1
p = 1
While c > 0
p = 0
b = c
While b > 0
If b And 1 Then
p = p + N
End If
b = int (b / 2) ' YOU MUST USE THE INTEGER PART NOT THE REST! asr more efficient fo division!
N = N + N
Wend
N = p
c = c - 1
Wend
MsgBox p ' the result of N!


Other 8 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.