Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Very, very large C# floating-point numbers

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.

like image 770
JustinT Avatar asked Jan 07 '09 19:01

JustinT


2 Answers

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?

like image 185
mackenir Avatar answered Sep 19 '22 00:09

mackenir


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 ?

like image 22
Charles Bretana Avatar answered Sep 22 '22 00:09

Charles Bretana