I've been learning (slowly) the Nim programming language via Rosetta Code.
I've run into a problem with the "bignum" package.
"~/.nimble/pkgs/gmp-0.2.5/gmp/pure.nim(19, 47) Error: invalid indentation".
I think I've installed, uninstalled this package several times.
I'm on MacOS 26.5 (Tahoe) with arm64.
Thanks, Ret_Bld_Engr
The error message shows an error with gmp and not bignum.
What is your version of nimble?
Try reinstalling the gmp Nim's package using Nimble.
Why is the problem in a quotation markdown format?
My experience with bignum is that it's only good for big numbers that have just a few thousand digits. If you want to work with really huge numbers, bignum is slow.
For instance, the largest Mersenne Prime found so far is 2^136_279_841-1 (see https://www.mersenne.org/). bignum takes too long to calculate this number. My question: what Nim package do you suggest for such huge numbers? I want to get this number as a string. (Interestingly, Python's big integer implementation is really good. In Python, I can get this number in about 30 seconds on my desktop machine).
Thanks for your reply.
New at this, didn't deliberately use the markdown format.
Using:
Nim Compiler Version 2.2.6 [MacOSX: arm64] Compiled at 2026-01-25
and
Nim Compiler Version 2.2.10 [MacOSX: arm64] Compiled at 2026-04-24
I think that the error refers to pure.nim, is that not correct? Why would nim care about the formatting of gmp itself?
Uninstalling and reinstalling changes nothing.
Thanks, Ret_Bld_Engr
Don't use bignum from nimble, it wasn't updated in 7 years.
There's a fixed version for Nim 2 here: https://forum.nim-lang.org/t/10377#69166
You can install it with nimble install https://github.com/adokitkat/bignum or similarly require it in the nimble file by using full url.
@rarino try out stint or theo libraries, they are probably faster: https://github.com/ringabout/awesome-nim#bigints
I also personally really like https://github.com/PMunch/mapm-nim , because it also provides arbitrary precision floating point numbers.
I got the latest mersenne prime with mapm in ~60 seconds, with python version taking around 85s on my machine.
theo is really just a stub at the moment. I never had the time to dedicate to it.
The bigints package is too buggy and slow, the package should be removed while division isn't fixed, it's a bad example: https://github.com/nim-lang/bigints/issues/123, and frankly the algorithms and data structure used are really really bad foundations to get any semblance of decent performance.
You can't just ask AI to fix it, you need to rewrite it from scratch.
The base algorithms are in theory easy: https://github.com/mratsim/constantine/blob/e6bee85/constantine/math_arbitrary_precision/arithmetic/limbs_multiprec.nim#L165-L228 but when you want to make it general, then you need to think about:
Now on assembly, it really depends. You can go faster than GMP on modular inverse or powmod / expmod (see my tutorial here https://github.com/status-im/nim-stint/issues/126) but for plain addition/substraction or multiplication you will need it.
frankly the algorithms and data structure used are really really bad foundations to get any semblance of decent performance.
I don't see how, as I said, iirc Python largely does the same thing and gets away with it.
You can't just ask AI to fix it, you need to rewrite it from scratch.
My guess about that bug is that it is a subtle one and I would be very curious to see someone (a human) use AI to very carefully to explain to us (other humans) what is wrong there. And fix it.
I would definitely read with great pleasure a blogpost like: “Fixing a subtle bug in an implementation of Knuth’s algorithm D for long division”
(I see looking back at that issue that somebody recently - aka 10 months ago - states to have the solution. Just having a fix - whether AI or not - is not sufficient, you need to understand what was wrong and be able to explain it plainly)