Question

If I wanted to compute numbers with hundreds of millions of digits (positive integers), which programming language would be best suited for that?

Currently I'm using python and the script is running and it was easy to code, but I have concerns for its speed.

I don't really know much about assembly at all so while it MAY be the fastest, I would rather not use that. Is C the best choice here?

The specific operations I have to use are *, -, % (mod), exponentiation, equality testing (if statements), and basic looping and some sort of outputting capability (console output for example).

Many thanks.

Was it helpful?

Solution

You can use GMP with plain C, but note that a lot of dynamic languages use it for arbitrary precision numbers, python too. You might not gain much by using C.

OTHER TIPS

GMP library with C/C++.

http://gmplib.org/

Here is your resource to read up on. This refutes the argument that C is fastest, unless you use the C99 restrict feature. If anything C++ is faster than C. It really comes down to the compiler understanding when two separate but sequential operations 'read' reference the same memory location. This allows the compiler to reorder the operations for optimization. It appears Fortran is best at doing this.

http://en.wikipedia.org/wiki/Pointer_aliasing

Also you can see here that Fortran blows C++ away at the Mandelbrot routine. But when it comes to text manipulation C++ appears to be tops.

http://shootout.alioth.debian.org/u32/fortran.php

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top