BigInt in Javascript

Back to Programming Languages forum

stubbalicious     2020-01-16 08:21:31

I have had trouble with a few problems now that involve large numbers, large enough to require BigInt, but I can't seem to be able to use it. I get the error message saying BigInt is not defined. Some of them I could skirt around with using modulous and dividing by ten. Am I not doing something right? Is there another way to deal with these large numbers?

Rodion (admin)     2020-01-16 09:46:16
User avatar

Hi there, it is a good question :)

Such problems - about "long arithmetic" really meant that people may try and implement long calculations manually, using arrays or strings.

Some languages provide ready long numbers (LISP was one of the first, but now Python and Java are most well-known for this).

But some other does not. JavaScript got BigInt at some point. But it seems our "sandbox" is using older version.

By the way, the site is written in PHP and checkers for problems too. PHP don't have long arithmetics "out of the box" so I myself needed to implement several operations with long numbers from scratch.

So you have two options:

  • either write your own brief implementation of bigints using arrays
  • or run the code at your machine with proper JS version or necessary libraries - and then just copy it and the answer to submission page.
Please login and solve 5 problems to be able to post at forum