SunQuest
           C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old April 16th, 2003, 10:21 PM
balance balance is offline
.
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 296 balance User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
[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?

Reply With Quote
  #2  
Old April 16th, 2003, 10:52 PM
MJEggertson MJEggertson is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2002
Location: Seattle WA
Posts: 863 MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 sec
Reputation Power: 8
Factorials get really big, really fast. You probably want to avoid integers all together and use floating point types, like a double.

Reply With Quote
  #3  
Old April 16th, 2003, 11:18 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,442 Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 h 55 m 33 sec
Reputation Power: 797
Try using the GMP library http://www.swox.com/gmp/

Reply With Quote
  #4  
Old April 18th, 2003, 10:18 AM
Jason Doucette's Avatar
Jason Doucette Jason Doucette is offline
jasondoucette.com
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Canada
Posts: 378 Jason Doucette User rank is Private First Class (20 - 50 Reputation Level)Jason Doucette User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 h 23 m 8 sec
Reputation Power: 6
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.

Reply With Quote
  #5  
Old April 18th, 2003, 01:03 PM
balance balance is offline
.
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 296 balance User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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)

Reply With Quote
  #6  
Old April 18th, 2003, 01:16 PM
Jason Doucette's Avatar
Jason Doucette Jason Doucette is offline
jasondoucette.com
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Canada
Posts: 378 Jason Doucette User rank is Private First Class (20 - 50 Reputation Level)Jason Doucette User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 h 23 m 8 sec
Reputation Power: 6
Quote:
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.

Reply With Quote
  #7  
Old April 18th, 2003, 01:24 PM
MJEggertson MJEggertson is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2002
Location: Seattle WA
Posts: 863 MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 sec
Reputation Power: 8
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)).

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > [c] bigger numbers?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway