-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
RFI: Integer vs Float in Lua 5.3 #3220
Comments
I think this is a perfectly sensible position to take. The Lua manual even says
so we can just have the manual say "NodeMCU's Lua is [or defaults to being?] compiled with LUA_32BITS. This comes with the usual caveats about inexact conversions between integer and float values: integers outside (-2^24, 2^24) have no exact floating point representation, and, of course, most floats do not have integer representations." We might wish to say, in PiN, something like "When programming in C, larger and smaller integer types (e.g., Are |
Yes For someone who has working code based on master but wants to move forward, what should the advice be? As I see it, the choices are: 1: Stick with the lua51 build -- but that won't be supported for ever What is our advice? |
We should probably require that all in-tree modules do something sensible in all four build flavors you mention. We might suggest that developers migrating up move in a "1-2-3-4" direction: test with |
Philip, forget 4. I am not going to do all the extra work to get an int-only version of Lua53 working and supported, when the current default does everything that an app developer would want. The trouble with 2 is that you haven't been fielding the issues about lack of RAM, and the current default helps address these. A 64 bit configuration is still build option, but not the default. You still haven't given a really world example of where a 32+32 configuration is going to cause material problems |
@pjsg Philip, I've been brooding about his one and I really don't understand how Lua53 is a new capability and the trade-offs and feature differences have been debated on these issues over this last 12 months. No changes have been introduced that haven't been previously discussed and agreed by those committers engaged with the threads. You seem not to have tracked these discussions and perhaps therefore the outcomes are a surprise to you, but this is outside everyone else's control. The major "feature breaks" arise from the Lua language and RTL changes 5.1 to 5.3 -- I didn't invent the sub-typing int vs numeric: this was introduced in standard 5.3, and because the standard implementation uses the same size for float and int types there will always be a loss of precision somewhere converting from int to float and back again. These was the same issue that I had to deal with over 50 years ago, when I first learnt FORTRAN IV. Developers will have a choice: stay with the (frozen) 5.1 or take the new 5.3 with its new features and face some conversion bumps. IMO, there isn't a magic sweet spot where we can cherry pick all that we want to retain from 5.1, but at the same time have all of the nice new 5.3 features. |
I had always used the integer builds because they were faster and used less memory. This lead me to not truly appreciate the difference between integer and number (because they were the same). Then, if you built a float version, all the integers continued to work as you can represent an int in a double exactly. The current master behavior of (say) rtcmem.write32 is not broken -- if you give it an integer value, it will store that value and will read it back correctly. When I switched to the new lua53 dev branch and started to work on one of my projects (a pendulum clock monitor), then I ran into the issue of the broken modules -- in particular timestamps were not represented correctly. [I had been using a float build I think].
and send them via mqtt to a server for recording. The You are right -- I have been a lot more involved with this than most users of the lua firmware. If I'm surprised, then I suspect that many others will be surprised too. It may be that the solution is to be upfront about the differences between the current dev and master and guide people to choosing the right option for their application. |
If you stay in integer then the overflow occurs at 2^31 -- same the old int builds. If you want mSec or uSec resolution, then why not just use the secs + usecs pair that you used with int builds, or even just do your own 64-bit build? The architecture isn't broken; the reason that |
Terry -- you don't need to make all of these changes -- I'm going to start in on some. |
BTW most of these assign the result of a |
Speaking as mostly a "consumer" here --- we have a fair amount of LUA code in currently shipping products which would have to be very carefully audited; And there are several issues I can already think of from the top of my head. These are mostly, but not exclusively, related to representing time, and calculating time differences. But it is the issues I can't think of that worry me... Given that a lot of this code is running on ESP32 modules, which have (comparatively) lots of RAM, we would probably end up configuring our NodeMCU builds for 64 bit numbers, both to save effort and to not have to worry about subtle problems hiding in rarely exercised code paths. So as long as that configuration remains supported, there would be at least one real-world use of it. If the 64 bit build config were to disappear at some point, however, we'd have to weigh the benefits of newer NodeMCU releases against the cost of those code audits, and I suspect we'd end up just sticking with the latest version that offers a 64 bit build. |
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. |
This has been discussed in various issues well as documented in the NodeMCU Reference Manual, the Lua 5.3 whitepaper and touched on in Programming in NodeMCU.
The consensus of debate was that the significant memory savings from moving from a 12 byte TValue to an 8 byte TValue were worth the edge issues than might arise from this. In essence this default build gives the RAM density of Lua 5.1 Integer builds but with the runtime convenience of being able to use floating point if needed. So:
sint_32t
quantities./
operator;//
is the integer divide operator.To give you some examples:
So I am requesting input from the active committers and any other contributors on the following:
The text was updated successfully, but these errors were encountered: