What would be BigNum solutions for Defold/Lua 5.1?

Hello!

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

4 Likes

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

Hi!

One year later, looks like I’m facing the same problem / having the same need :slight_smile:

I’m also working on an idle game (prototype), so I need to be able to use super big numbers… (which doesn’t seem possible in Lua)

I’ve downloaded the lmpapm library, but I… don’t know how to use it.

I just copied the content of “test.lua” content in my main script, but it requires a non-lua file and of course it doesn’t work:

image
image
image

So… I don’t know what to do at this point :thinking:

Is there a simple way to make it work in Defold?




In case it’s not possible, it looks like this workaround can be useful even though it’s not 100% accurate.
image


=> I’m supposed to have a 100% round integer but the accuracy level seems to be good enough for my needs. So I can probably do something with that (same for anyone wanting to create an idle game with big numbers).




Note: would be nice to have a Defold extension to deal with big numbers (anyone developing an idle/big number-based game would use it), unfortunately as you can see I’m far from being able to develop it myself…

1 Like

Have you tried putting the files in that folder that it complains about?
I.e. the file it’s missing is

/lua-modules/libs-external/limath-104/src/imath.lua

Does it exist in the project?