Best coding language for dealing with large numbers (50000+ digits)

有些话、适合烂在心里 提交于 2019-12-07 07:23:55

问题


Can you recommend good languages to do math with large numbers in?

So far I've used Actionscript 2 and Objective-c and with Objective-c even using NSDecimalNumbers I was limited to 32 digits in my calculations... I would need at a minimum to be able to calculate with numbers fifty-thousand digits long.


回答1:


Perhaps Haskell will appeal to you.




回答2:


Python has arbitrary-length integers and uses them transparently, so you don't need any special code or classes for this.

>>> len(str(math.factorial(123456)))
574965



回答3:


Try also bc, which is probably already installed in your machine.




回答4:


Try java with its BigInteger Class or you can look at writing a small library in C. If the Math is fairly simple you can always use arrays.

Perhaps try Matlab (not sure)




回答5:


Nowadays most languages have some kind of support for arbitrary length numbers, natively on the language or via some external library (i.e. gmp).

The only important difference* is the level of integration within the language. For instance, in C++, Python, Perl, SWI-Prolog, Haskell, C#, etc., big-ints can be manipulated as any other built-in numeric type using the standard math operators. On the other hand in languages not supporting operator overloading as C, Objective-C, Java, etc. you have to use the library functions explicitly.

Depending on the pervasiveness of big-int operations on your application it may pay off to switch to a more big-int friendly language or not.

update

[*] well, obviously, correctness and speed also matter. But, as most languages use GMP under the hood, there shouldn't be mayor differences in that regard. Maybe math-oriented (and expensive!) languages/applications as Mathematica or Maple providing their own big-int implementations can have some advantage here.



来源:https://stackoverflow.com/questions/14723583/best-coding-language-for-dealing-with-large-numbers-50000-digits

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