dimanche 24 avril 2011

n! aka Factorial

So i have just finished that mathematic course wich uses the factorial Probabilities and/or Combinations and Permutations (Damn i still don't understand it very well x)) and i have decided to code an asm program that can calculate factorial wait! do you know what is it?! well Factorial is means to multiply a series of descending natural numbers. ( symbol: ! )
For exemple:
1! = 1 why? cuz they had generally agreed that 0! = 1
2! = 2*1 = 2
3! = 3*2*1 = 6  
4! = 4 × 3 × 2 × 1 = 24  
7! = 7 × 6 × 5 × 4 × 3 × 2 × 1 = 5040

you wan't more?  

you think they're large see the next ones :) i counted some of themusing calc of wind0ws x)
100! = 9,3326215443944152681699238856267e+157
200! = 7,8865786736479050355236321393219e+374
300! = 3,0605751221644063603537046129727e+614
400! = 6,4034522846623895262347970319503e+868
500! = 1,220136825991110068701238785423e+1134
1000! = 4,02387260077093773543702433923e+2567
2000! = 3,3162750924506332411753933805763e+5735
3000! = 4,1493596034378540855568670930866e+9130
4000! = 1,8288019515140650133147431755739e+12673
5000! = 4,2285779266055435222010642002336e+16325
10000! = 2.8462596809*1035,659
25206! = 1.2057034382*10100,000
100000! = 2.8242294080*10456,573
205023! = 2.5038989317*101,000,004
1000000! = 8.2639316883*105,565,708
1,0248383838*1098! = 101.0000000000*10100
1,0000000000*10100! = 109.9565705518*10101
1,7976931349*10308! = 105.5336665775*10310
amazing x) 
here is the crappy calculator source don't get shocked x):
mov esi,12d
mov ecx,esi
Fact0:
dec ecx
imul esi,ecx
mov edx,esi
mov ebx,edx
xor edx,edx
xor esi,esi
mov esi,ebx
cmp ecx,1
jnz Fact0
PS: at the moment it can only calculate to 12!
and btw if you know some tricks to count large numbers tell me please!

Credits: Wikipedia