Closed mk-pmb closed 3 years ago
@mk-pmb Can you please check the fix in the PR #3270?
I tested it with this firmware and this program. The results show that now the + is the same on NodeMCU as on Ubuntu's LUA. Thank you for fixing it! :+1:
However, at the same time they indicate they have a different interpretation of the number of spaces when the sign is omitted. Also you might wonder why I used 3.1410 as the number, not 3.1415… that's because they also have different opinions about rounding. Should we extend the issue and PR to tackle that?
Thanks for testing. I'll try to have a look at both issues. If there's easy way to fix it it can be done. Maybe we should continue the discussion directly in the PR.
This didn't get picked up as fixed automagically. If it should remain open, please feel free to reopen it!
I tested with this firmware built from commit 64bbf006898109b936fcc09478cbae9d099885a8 = the current dev branch. The results are as from my previous test above.
@vsky279 Since the MR is merged now, I guess it would be confusing to continue the discussion there. Will you make a new MR for the spacing and/or rounding bugs? Shall I open issues for them? If the MR seems easy maybe we should just extend and re-open this issue.
You were too fast guys. I suggest reopening this issue rather than opening another one.
I have almost ready the PR for testing for the ' '
flag (e.g. % 8.3f
).
As for the rounding - I think it is not something to be corrected. I think the difference @mk-pmb observes between Ubuntu Lua 5.2 and NodeMCU Lua 5.3 is due to the fact that we are using 32bit float while Ubuntu is using 64bit double.
3.1415 does not has precise representation in 32bit float. It is in fact stored as 3.141499996185303 (0x40490e56 = 2.00000000 * 1.5707499980926514
) so when rounded to 3 decimals we are still at 3.141. ~~However I don't know how C manage to print 3.1415 instead of 3.141499...
Maybe some more experience programmer can elaborate on this.~~
print(3.1415)
prints number using %.7g
format so 3.1415 prints correctly.
(If anyone else wonders: He's using big endian notation.) Maybe they multiply by 10**precision first, or calculate the next decimal digit and decide based on that. Update: In-depth discussion of sprintf rounding modes. Quote by Vincent Lefèvre:
You get different results because the C standard doesn't specify these cases and the C libraries are different.
Would be waaaay to easy if computer rounding would be the same as we learned in school math.
@mk-pmb please test the PR #3283.
Will do, probably tomorrow. Meanwhile: For changing the rounding I think we should ensure a wide consensus, do we have that? Edit: I see it's being discussed in the PR.
Definitely there needs to be wide agreement. This is also why I have two separate commits.
Done for ESP8266. Meanwhile I got an ESP32 as well, but it may take another few hours until I can test on that. I can't currently test on that so nevermind.
I think that this should be solved with the merging of the snprintf implementation. Can you verify?
I tested this already. Both flags '+' & ' ' work fine with the new snprintf implementation.
The double rounding - it would be nice to have it implemented. Is it possible to submit a PR on source files provided by a submodule?
I think that you should submit the PR to the original module....
On Sun, Oct 4, 2020 at 5:50 PM Lukáš Voborský notifications@github.com wrote:
I tested this already. Both flags '+' & ' ' work fine with the new snprintf implementation.
The double rounding - it would be nice to have it implemented. Is it possible to submit a PR on source files provided by a submodule?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/nodemcu/nodemcu-firmware/issues/3265#issuecomment-703321177, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALQLTKCY2BBJF4S74HEC2LSJDUZVANCNFSM4QQ5VJUA .
I think that with 64-bit doubles (PR #3225) there's no need to have the double rounding implemented.
If someone needed precise rounding with doubles it is achieved ("%.3f"%3.1415
gives 3.142
with #define LUA_NUMBER_64BITS
). So think we can close this issue.
Closing by request of @vsky279.
Expected behavior
My number has a plus sign, as on Ubuntu:
Actual behavior
No sign in the REPL on my ESP8266 (using this firmware built with
LUA=53
from current dev branch + tmr fix.Test code
NodeMCU startup banner
Hardware
ESP8266 LoLin v3