'************************************** ' Name: Quick N! (Factorial) calculation ' using Double! ' Description:Explain a metodology ' based on "russian muls" ' for a quick computation of N! ( factorial) ' suggestion and optimization are wellcomed! ' By: michele berardi ' ' ' Inputs:None ' ' Returns:None ' 'Assumes:None ' 'Side Effects:None 'This code is copyrighted and has limite ' d warranties. 'Please see http://www.Planet-Source-Cod ' e.com/xq/ASP/txtCodeId.38817/lngWId.1/qx ' /vb/scripts/ShowCode.htm 'for details. '************************************** 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 algorit ' hm ' is adapted to the vb limits.. ' you can use long or int instead of dou ' ble ' for small calculation.. ' some tips require the use of asr (arit ' metic ' shift right) ' instead of division by 2! ' and code optimization instead - 1 you ' can.... ' a good exercize of optimization... enj ' oy! ' (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!