1

I am writing a program in Swift to create a Pascal's Triangle. The results get very interesting when the number of rows gets very large. Unfortunately, at the same time, the numbers in each cell get very large, and when you get to the 68th row, the number in one cell is the sum of 9989690752182277136 plus 11923179284862717872. This causes a runtime error, which I assume is because it has overflowed the UInt64 variable.

My question is this: how is it possible to write such a program for very large integers in Swift? I don't care if it runs on a Mac or an iPad, I just want to get the results. Is this a limitation of the hardware? Is it a limitation of the simulator? Or of the language? Is there a combination of language and hardware that would work that doesn't require a supercomputer?

I guess I am trying to figure out whether I need a more powerful computer, another language, or both.

Thanks in advance.

Jonathan Rachlin
  • 361
  • 3
  • 16
  • Well, Java has `BigInteger` that allows arbitrarily large numbers. I think Haskell and Python both have similar Int types. Providing you have enough memory, yes, it is possible to represent giant numbers. – Carcigenicate Jul 10 '17 at 23:12
  • https://github.com/kirsteins/BigInteger swift version – andykkt Jul 10 '17 at 23:13
  • It seems like your question is a duplicate of the one I've linked. Also related: [BigInteger equivalent in Swift?](https://stackoverflow.com/q/25531914/2415822) – JAL Jul 10 '17 at 23:21

0 Answers0