我应该如何处理算法与庞大的数字

我应该如何处理算法与庞大的数字

本文介绍了C#中:我应该如何处理算法与庞大的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个应用程序,其中涉及算术堆积如山的数字,有很多数字。我有previously撰文指出,简化定义为字符串,然后用慢算术字符串函数处理大的数字类。这是做到这一点的最好方法是什么?如果不是这样,我应该怎么解决这个问题?请问C#有任何内置的这种情况?

I'm writing an app which involves arithmetic with humongous numbers, with very many digits. I've previously written a class that simplifies handling big numbers by defining them as strings and then using slow arithmetic string functions. Is this the best way to do it? If not, how should I approach this problem? Does C# have anything built-in for such situations?

推荐答案

.NET 4将通过BigInteger的类型本内置的。这是自称为pretty的调整良好,并应表现非常好。

.NET 4 will have this built in via the BigInteger type. This is claimed to be pretty well tuned and should perform very well.

有关3.5和更早的版本,你可以抓住的BigInteger从动态语言运行时来源。 (见例如<一href="http://dlr.$c$cplex.com/sourcecontrol/changeset/view/40021?projectName=dlr#694008">http://dlr.$c$cplex.com/sourcecontrol/changeset/view/40021?projectName=dlr#694008并深入到Src蛋白/运行/ Microsoft.Dynamic /数学)。我不知道这是否已被调整为高度作为.NET 4的BigInteger类型,但它仍然应该比你的字符串版本更有效,因为它在内部重新使用整型$ P ​​$ psents的大数字,并使用整数运算进行运算。

For 3.5 and earlier, you can grab an implementation of BigInteger from the Dynamic Language Runtime sources. (See e.g. http://dlr.codeplex.com/sourcecontrol/changeset/view/40021?projectName=dlr#694008 and drill down into Src / Runtime / Microsoft.Dynamic / Math.) I don't know if this has been tuned as highly as the .NET 4 BigInteger type, but it should still be more efficient than your string version because it internally represents the big numbers using integral types and performs arithmetic using integer operations.

这篇关于C#中:我应该如何处理算法与庞大的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 03:15