4 ms·
AFAIK, Lua has only one numeric data type, double-precision floating-point numbers. That kind of scares me -- I like my integers integer and not approximated. D
by limmeau 17y ago
AFAIK, Lua has only one numeric data type, double-precision floating-point numbers. That kind of scares me -- I like my integers integer and not approximated. Does that, in your experience, cause problems in practice?
(Yes, I know that in principle, IEEE 754 Doubles can represent all 52-bit integers precisely (give or take a few bits), but still I don't feel comfortable).
- silentbicycle 17y agoIt hasn't been a problem for me. There are a couple arbitrary precision libraries for Lua, so I just use those when it would matter. I've used: * lbc: http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/#lbc * GMP wrapper: http://members.chello.nl/~w.couwenberg/ and there are more linked here, under "Math": http://lua-users.org/wiki/LibrariesAndBindings http://lua-users.org/wiki/LibrariesAndBindings Lua uses doubles by default, but you can change the numeric type quite easily via luaconf.h (http://www.lua.org/manual/5.1/manual.html#lua_Number http://www.lua.org/manual/5.1/manual.html#lua_Number), if you need to work on a platform for which doubles are too large, if you'd prefer to use 64-bit longs, etc. Lua is designed to be small enough that you can just include the whole language in your source tree as a library, if you need a custom version. Think of it as a 200k .dll/.so that gives your C program a scripting interface / config file parser, a generational garbage collector (for the Lua portion), and a great string and hash table library. (The standalone Lua interpreter is just a thin wrapper to add a REPL to the C API.) Lua code also works well as a data serialization format; it's very similar to JSON, and the Lua compiler has been tuned specifically for rapidly compiling data dumped as Lua literals.
- limmeau 17y agoThanks! I'll try that sometime.