4

What would be the best programming language for very large arrays and very large numbers?

  • With arrays over 30,000 indexes
  • And numbers over 100 digits

Also it needs to be efficient, or easy to make efficient.

Thanks.

Andriy M
  • 76,112
  • 17
  • 94
  • 154
Simon Smith
  • 49
  • 1
  • 2
  • 10
    An array with 30k elements is **not that large**. – Matt Ball Feb 17 '11 at 13:33
  • @Matt not if the elements are large ;) – Kakira Feb 17 '11 at 14:05
  • @Kakira: in most languages, an array of "large" objects would be just an array of pointers to those objects, which itself is not that large. Even on a 64-bit system, an array of 30k 8-byte pointers is <235 kilobytes. The objects themselves would take up more space, but the fact that there are 30k of them is basically irrelevant: the system would just need sufficient RAM. – Matt Ball Feb 17 '11 at 14:35

4 Answers4

5

Almost any programming language worth its salt should have these characteristics, and frankly I don't think I'd want to use any language that can't handle arrays of 30,000 elements. I'll list a few that have good support for very large numbers:

python. Python 3 has automatic support for large numbers as the default number type grows as necessary, and has some really awesome math libraries. Other languages may be ever so slightly faster, but unless for some reason you know for sure that python won't be good enough I'd start there.

C#. This will mostly bind you to windows, but its very popular, fast, and meets your requirements.

Java. Cross platform, mature support with BigInteger.

Haskell. Pretty seamless conversions to large numbers and powerful math support. If you have a strong mathematics background Haskell will feel pretty natural. If you already know functional programming or don't mind devoting a fascinating few hours to learning it, this is a good choice.

C/C++. Very fast, but a little more complex to develop in. You'll probably get better results in large number support with something else. I'd only look into C++ if you've tried optimizing code in another languages and its still not fast enough, unless you have a specific reason to not use an intermediately compiled language.


The truth of the matter is that its hard to find a programming language that doesn't support these things, and if you could I probably wouldn't use it for anything because its probably not that mature. Do you have any other requirements that would help us narrow it down further for you? :D

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Gordon Gustafson
  • 40,133
  • 25
  • 115
  • 157
  • Actually, it is not *that* hard to find programming languages that (whose existing implementations) are not particularly efficient ;) – toochin Feb 17 '11 at 13:57
  • @toochin, that is true, but unless you know for absolute certainty that your performance requirements would justify making speed top priority in language choice, meaning you've tested code in multiple languages and still haven't gotten the speed you need, I wouldn't worry about performance too much. I agree that it is pretty obvious you wouldn't want to use a language like javascript for this. :D – Gordon Gustafson Feb 17 '11 at 14:01
  • C/C++ doesn't support large numbers; you have to implement them by yourself. – Rontogiannis Aristofanis Oct 21 '12 at 08:06
4

The array is not the issue. Numbers consisting of 100 numerals (digits) is a huge issue. I don't have a good answer to the question (out of date as it is) but as this comes up readily in Google I'll mention that most languages only support between 32 to 64 bit numbers. (I know that the C family of languages, PHP, as3 and Java don't support massive numbers.)

For example a 32 bit number would allow a range of 0 to 4,294,967,295 (2^32-1) which is only 10 numerals (Actually more like 9 because the limit is by size, not numerals), a whole order of magnitude less than the required 100 digits the questioner was after.

That said I know that there are cases of people implementing support for large numbers in C and AS3...

shaedo
  • 41
  • 1
1

Python with NumPy is probably what you want.

Creshal
  • 493
  • 1
  • 4
  • 15
0

I always found Fortran to be quite nice when dealing with arrays, esp. with multi-dimensional ones. If you are dealing with very large numbers, you will probably need to define your own data type or live with a loss of precision, though. Or use this: http://www.fortran.com/big_integer_module.f95 .

But it depends a bit on what you want to do. Fortran is nice for numerical computations, and not so nice for about everything else.

toochin
  • 332
  • 1
  • 2
  • 9