New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lua precision problem when using float for lua_number #4564
Comments
My suggestion: use double as before. I would really urge for a quick decision on this, since this has a major impact on a lot of things. Pro:
Con:
|
Would you please read the threads ? |
I highly doubt you would "experience" a few cycles at 120 or 168MHz. 😉 We're talking CPU-level speeds here, which is more important for overall well-being of the radio (you know, sending pulses and such) than to the Lua scripts themselves.
I'm not really sure what this means, but the whole problem with using
This has nothing to do with the bit32 library or using bitfields specifically. It is just much easier to notice a small change in value when each bit is checked individually. The underlying issue is that Lua's handling of integers is (IMHO) broken. The only reason no one has cared/noticed before is that (apparently) no one needs to use integers >53 bits long. |
Sorry, just noticed the other thread was closed, and this one opened. Didn't see the short term solution that was offered there. thanks for the explanation. Saving memory can be done by storing for instance a telemetry value you fetch by getValue in one "byte" (or whatever power of 2) of the integer, and the next value in the next. This allows to store multiple values that will physically have a limited range (like altitude, that I don't expect to be above 1024 meters) in one integer. I use this for storing up to 10 graphs with 64 points without lua going out of memory. As for the bit library, sure, there is no reason specifically, but a lot of commun (LUA) scripts I know use 32 bit integers and bit operations on them. Bitoperations only make sense for those scripts if LUA supports the full 32 bits integer range. So practically yes, the people using the bit library probably do so because they need to handle 32 bit integers. But specifically, no, you are right. Well, I did use "probably" :) I'm happy with the short term decision. |
Yes, and the reason this saves memory is that each numeric allocation in Lua is actually 64 bits (of which 53 are usable for the purposes you describe). Storing one byte in 64 bits obviously isn't the most efficient way to go. If Lua had a concept of actual EDIT: So in case it's not obvious already, one of the reasons for moving from
Just out of curiosity, do you only use 32 bits per storage "container," and if so why did you stop at 32 (vs., say 64 or 53). |
Just out of curiosity, do you only use 32 bits per storage "container," and if so why did you stop at 32 (vs., say 64 or 53). Lazyness in order not to bother about the top part difficulties. |
Another possible option to investigate (instead of Lua 5.3): LuaJIT Looks like it has support for actual number types as well as other optimizations. Still in active development: https://github.com/LuaJIT/LuaJIT/tree/v2.1 Adds a very interesting extension allowing quick integration of C/C++ functions, even using native C code from within Lua: http://luajit.org/ext_ffi.html This may be a viable replacement for the current |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
See #4560. Long term solution is still under the discussion, here are the possibilities:
The text was updated successfully, but these errors were encountered: