Need Help implementing LMAPM or another arbitrary-precision math library.

Bobert13

Prince
Joined
Feb 25, 2013
Messages
346
Does anyone out there have any experience with implementing an arbitrary-precision math library in Lua? I'd like to try this approach at solving floating point inconsistency issues resulting in desynchronized maps when using certain user-created mapscripts in multiplayer.

I've no experience with tarballs and makefiles and all that jazz and I can't for the life of me figure out how to build the library and make it available in the mapscript I'm working on. I have MinGW installed under CodeBlocks but was able to compile a lmapm.dll through the following command line:

Code:
MinGW32-gcc.exe -c C:\users\*redacted*\downloads\mapm\lmapm.c -o c:\users\*redacted*\downloads\mapm\lmapm.dll

I had to place this .dll in the root Civ V installation directory and the following line did recognize it, but threw a "%1 is not a valid Win 32 application" error:

Code:
bc = require"lmapm"

[rhetorical rant]Why? WHYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY? Seriously, why do developers distribute software in such a, mind-numbingly inconvenient, insanely frustrating, format?[/rhetorical rant]
 
After some time I found LuaBigNum and LuaBigRat which appear to be librarys written entirely in Lua (http://oss.digirati.com.br/luabignum/). This means no compilation, no .dlls, just a simple include...

EXCEPT, I can't even get the script I'm working on to include them. I've tried placing BigRat.lua in \Documents\My Games\Sid Meier's Civilization V\Maps, the game's root directory, \Steam\~\Sid Meier's Civilization V\Assets\Gameplay\Lua, and probably a few other locations. None of them seem to be getting included as "BigNum" and "BigRat" are undefined according to World Builder... What needs to be done to get these so my script can see them?

Edit: After some preliminary testing and overlooking these, they don't seem capable of doing what I need anyways. I'd like to get back to floating point for the final number (or at least a decimal instead of a fraction) which doesn't seem possible with these.
 
I'm fairly sure that the CiV Lua implementation is intentionally sandboxed to prevent you from including external libraries for security reasons. The 'include' we have isn't the real Lua include.

I'm using LuaJIT (which replaces lua51_win32.dll) so unless it's somehow prevented in the game itself, or AntmanMike's compiled LuaJIT has the same limitation, I don't think this is the issue. As I said, I got it to recognize that lmapm.dll existed. I must've made a mistake compiling it or it's not distributed in a form that can run directly on Windows or one of about 3000 other issues.

I've started the process of writing my own finite precision math library that breaks numbers down into three half-precision floats (they're technically still lua numbers (doubles) but I'm limiting them to three digits and handling the decimal point separately). I've got conversion formulas, add and multiply working, now just to do subtract, divide, exp, mod, and maybe a few others. I'll be keeping an eye on this thread though, as I feel an external C library is probably going to increase the performance dramatically over whatever I can hodgepodge together.
 
Back
Top Bottom