1. No Profile Picture
.
Devshed Newbie (0 - 499 posts)

Join Date
Dec 2002
Posts
296
Rep Power
13

#### [c] bigger numbers?

i'm messing round with a poisson random distribution formula and it loops through using the loop number in the equation. one part of it is a factorial like in mathematics 4! which means 1 X 2 X 3 X 4 = 24. by the time i've got to the 13th loop the result (it's the loop number that gets factorialised) exceeds an unsigned long. how can i continue to loop while getting and being able to use the correct factorial result. how can i get bigger numbers basically? possible?
2. No Profile Picture
Contributing User
Devshed Novice (500 - 999 posts)

Join Date
Jan 2002
Location
Seattle WA
Posts
863
Rep Power
15
Factorials get really big, really fast. You probably want to avoid integers all together and use floating point types, like a double.
3. Try using the GMP library http://www.swox.com/gmp/
4. double has a max range of 1.7E+308, which is enough to compute 170! = 7.2574E+306, so I would use this. If your compiler supports long double, you can compute much larger numbers.
5. No Profile Picture
.
Devshed Newbie (0 - 499 posts)

Join Date
Dec 2002
Posts
296
Rep Power
13
yup, it's getting to the 169th loop now, then it goes to infinity. the factorial number is 307 digits long at that point! that's with a double. my compiler isn't having long double. double's long enough. never realised there was so much difference between double and int (i knew there was some, but not 280+ digits worth)

so there's no need to use a library to extend it. thanks. :)

does anyone know anything about poisson curves? the results from it are lop sided.
Code:
```m = 10  (average number of random occurrences per interval)
Probability of occurrences in intervals :
------------------------------------------------------------------
0: 0.000045   0.00%    < probability of no occurance
1: 0.000454   0.05%
2: 0.002270   0.23%
3: 0.007567   0.76%
4: 0.018917   1.89%
5: 0.037833   3.78%
6: 0.063055   6.31%
7: 0.090079   9.01%
8: 0.112599   11.26%
9: 0.125110   12.51%
10: 0.125110   12.51%    <<<<
11: 0.113736   11.37%
12: 0.094780   9.48%
13: 0.072908   7.29%
14: 0.052077   5.21%
15: 0.034718   3.47%
16: 0.021699   2.17%
17: 0.012764   1.28%
18: 0.007091   0.71%
19: 0.003732   0.37%
20: 0.001866   0.19%
21: 0.000889   0.09%
22: 0.000404   0.04%
23: 0.000176   0.02%
24: 0.000073   0.01%
25: 0.000029   0.00%```
you'd expect, seeing as the input number is 10, that 10 would be at the height of the curve and it'd be fairly symetrical either side of 10. but it isn't. should it be like that, or is it my code do you think? (i'm guessing it's my code)
6. Originally posted by balance
never realised there was so much difference between double and int (i knew there was some, but not 280+ digits worth)
A double takes 8 bytes of memory. A long int also takes 8 bytes of memory. 8 bytes of memory can contain exactly 2^(8*8) = 2^64 = 18,446,744,073,709,551,616 different possibilities. Therefore, double does not have 280+ digits worth of more information. In fact, since several combinations of 64 bits in a double mean the same floating point number, a long int can actually store more different combinations of numbers than a double.

The true difference in the way they use the 64 bits to store a number is the fact that a double has bits reserved for storing an exponent. So, it can store a number like 1.234E+89. However, since it can only store about 15 or 16 decimal digits of accuracy, you can try to store 1.2345678901234567890E+89, but only 1.23456789012345E+89 is actually stored. Here's a detailed article explaining exactly how they are stored.
7. No Profile Picture
Contributing User
Devshed Novice (500 - 999 posts)

Join Date
Jan 2002
Location
Seattle WA
Posts
863
Rep Power
15
I don't know too much about Poisson statistics, beyone how it relates to sampling noise at low numbers of count events. One of the main point of Poisson statistics is that the curve is not symmetric as you get to lower number of occurrences. It only becomes symmetric as m gets very large, to the point where the error introduced in the sampling of m becomes irrelevant (when m >> sqrt(m)).