views:

858

answers:

3

I am doing some population modeling (for fun, mostly to play with the concepts of Carrying Capacity and the Logistics Function). The model works with multiple planets (about 100,000 of them, right now). When the population reaches carrying capacity on one planet, the inhabitants start branching out to nearby planets, and so on.

Problem: 100,000+ planets can house a LOT of people. More than a C# Decimal can handle. Since I'm doing averages and other stuff with these numbers, I need the capability to work with floating points (or I'd just use a BigInt library).

Does anyone know of a BigFloatingPoint class (or whatever) I can use? Google is being very unhelpful today. I could probably write a class that would work well enough, but I'd rather use something pre-existing, if such a thing exists.

+1  A: 

Do you really need 28 digit precision? Could you use floating point for some calculations?

(double to be exact: ±5.0e−324 to ±1.7e308)

Arkadiy
+10  A: 

Use units of megapeople to achieve more headroom.

Also, Decimal lets you have 100,000 planets each with 100000000000000 times the population of the Earth, if my arithmetic is right. Are you sure that's not enough?

mackenir
You're correct. I was working under the assumption that Decimal was a 64-bit data type. Now that I look at it more closely, I see that it is 128-bit, and more than big enough.
JustinT
Blimey, I just noticed how large a decimal can be...
flq
+2  A: 

Even if each planet has 100 billion people, the total is still only 1E16. This is well within the limit of a signed 64 bit integer (2^63 goes to 9,223,372,036,854,775,807 which is almost 1E19...

You could go with a Million Billion people per planet, with 100000 planets before you got close to the limit...

As to fractions and averages and such, can't you convert to a Float or double when you do any such calculations ?

Charles Bretana