Very, very large C# floating-point numbers

三世轮回 提交于 2019-12-23 09:15:53

问题


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:


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?




回答2:


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 ?




回答3:


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)



来源:https://stackoverflow.com/questions/421612/very-very-large-c-sharp-floating-point-numbers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!