-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Calling round() inside print() result differs between v2.4.2 and v2.5.0-beta2 #5530
New issue
Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “No 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? No Sign in to your account
Comments
If this credible: http://www.cplusplus.com/reference/cmath/round/ |
Either cast it to an int or specify the precision in print : |
That makes no sense at all. The reasons behind some of the contents of Arduino.h are other, and some of that explanation hints at it: they didn't have the standard implementation way back when they started out, and by now they've entrenched themselves for historical and backwards compatibility reasons, bugs and all. Here, we try to stick to the C++ standard, and to standard implementations, because not doing that leads to madness. If other sketches are found to behave differently as a result, those sketches need to be fixed. That's a good thing. It has already happened before, e.g. with abs() => std::abs(). @penfold42 shows that we comply with the cplusplus reference. Closing as non issue. |
Where did "Arduino is not standard C++, but some sort of language of its own that is based on C++" come from? I don't see that anywhere in the thread. Rather than aiming for brevity, I should probably have gone on to explain what I found most troubling about this change in behaviour. The header file "... cores/esp8266/Arduino.h" contains this line:
The line is the same in both 2.4.2 and 2.5.0-beta2 so it should be clear that the intention of the author(s) was that both implementations should have the same behaviour. If that #define had disappeared in the v2.5.0-beta2 then it would be clear that the math.h implementation was now in force. The #define is still present so I don't understand how the behavioural change has come about. If we makers can't rely on reading the code to understand behaviour then I think we are on a very slippery slope. |
Sigh, I thought that macro was removed already. Looks like our Arduino.h needs some further cleanup. The mention comes from the link to issue 6098 in the arduino repo, linked by @Makuna . I'm reopening to cover the cleanup in Arduino.h . |
I am sorry to hear that "here" we don't stick to the Arduino standard. I don't agree with breaking the Arduino standard as all it leads to is more support issues. There was a reason we had that "fix"/"change", it was to keep compatiblity. Get Arduino to change first, then follow. It seems that they will at some point but they haven't yet. |
@Makuna I feel I need to clarify something at this point. Arduino has a reference implementation of a core, and the api of that reference is mimicked in cores implemented for other microcontrollers in order to maintain compatibility. That reference implementation doesn't have revisions, there is no committee that gets together periodically to discuss changes, there is no publication by a standards organization, and the documentation is only of the api meaning, and not of the behavior in detail. In fact, the Arduino reference docs don't even mention argument types or return type for functions, and for this particular case, it doesn't even mention round() as a function. Therefore, Arduino is not a standard. C89/99/11/18 are standards. C++11/14/17 are standards. Even the AVR-libc, isn't a standard, but rather an arduino port of the standard C library for AVR. Which, btw, has
Point of fact, the issue you linked was opened 2 years ago, was discussed for a year after that, and is currently without even a milestone assigned. I have had a discussion or two with arduino guys regarding changes (not necessarily related to the topic at hand), and it has been explained to me in no uncertain terms why they resist change, even for fixing known bugs. It is my personal view that their lack of agility hampers users more than it benefits them, so I do not consider it wise to spend effort in that direction. Instead, I rather lead the way, showing what is correct and works well, and let the results ripple outwards. As I said, this has happened at least once already, and I expect it will happen again. Leading by example is better than pushing repeatedly against resistance, and waiting around just lets users hit the same old bugs over and over again.
Compatibility in the API is a priority. Compatibility with known bugs is not. As stated in the link, the macro behavior is buggy and unpredictable.
I don't agree with this. Entry level developers should deal with learning and experimenting, and not with brokenness and ancient bugs. But that's just me. |
Basic Infos
Platform
Settings in IDE
Problem Description
Under version 2.4.2, round() appears to return an integer quantity. Under 2.5.0-beta2, round() appears to return a real quantity. I am inferring this from a change in print() behaviour.
MCVE Sketch
Debug Messages
Output from compiling under 2.4.2 libraries. Note ABSENCE of decimal places for "inline =" values. This is the expected behaviour.
Output from compiling under 2.5.0-beta2 libraries. Note PRESENCE of decimal places for "inline =" values. This suggests print() is treating the return value from round() as a real quantity. This is unexpected.
The text was updated successfully, but these errors were encountered: