What would be BigNum solutions for Defold/Lua 5.1?



I need to work with really big numbers that go way beyond Lua limits. I liked this library, but it needs Lua 5.3…

There is also this BigNum library, but the rational version don’t seems quite what I want (It works with “x / y” format, I want the whole value directly). And I’m not capable of creating such library myself, it is way out of my league.

So, would anyone know a possible solution? Is there any big number libraries I could use with Lua 5.1?



Hi @rafael-lua!
Although I don’t know about any “big num” libraries, I’m curious about your use case? Perhaps you can tell us a bit more about what you want to do, and maybe we can help?



Sure thing. I work with incremental games. Numbers go up non stop, very often exponentially. Lua precision for integers goes only to 2^52. I imagine that floats are even smaller for precision. BigNum libraries (like this in js) would allow me work with obscene numbers without losing much precision and without limit.

Without such library, I have a very limited value to work with (For this genre of game), up to quadrillions more or less.



I think this one by Luiz (one of the Lua creators) would be a great candidate to turn into a native extension: http://webserver2.tecgraf.puc-rio.br/~lhf/ftp/lua/#lmapm



Oh, that seems very nice. I will give a try, but messing with native extensions looks hard.