How does one do math with VERY large numbers?

I was playing around with Desmos, and I came up with this. Obviously, 6.63 x 10^303 is quite a bit larger than a 64 bit unsigned integer. If you had to program a calculator that could handle such large numbers, how would you do it?

Posted May 30, 2017, 5:22 AM UTC

23
SurlyInTheMorning•

You'd use arbitrary-precision integers. Each digit is a machine integer, so that your number can have as many base-2^64 digits as memory can hold.

4
Holy_City•

In addition to that you can combine it with block floating point operations to do arithmetic on arbitrarily large (or small) numbers.

2
POGtastic•

I wrote a really rudimentary BigNum library a while back. It stores a vector of integers for the digits and multiplies / adds / divides them with grade school arithmetic.

In real life, you want something like GMP, as they're a lot more efficient.

Alternatively, you can use a language like Python or Haskell, which supports arbitrary precision arithmetic out of the box.

1