-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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
Small potential issue with disarming #9277
Comments
Small nit-picks are always appreciated. We should try using std::numeric_limits on NuttX, otherwise what about the NAN macro? I believe it's a GNU extension, but that should be fine. |
Pull request - #9280 |
@ZacharyTaylor while we're on the subject do you have any thoughts for safe floating point usage across the code base? Currently we have Question: Should we consider going to full
Reference: GCC Floating Point Math https://gcc.gnu.org/wiki/FloatingPointMath |
Disable math-error in #9281. |
Thanks a lot for the quick reply and pull request I will try give it a good look through either tomorrow or Thursday. I am by no means an expert on compiler optimizations or floating point numbers. However, I feel that the current practice of setting an output to nan to disable it may cause some potential issues with the optimization flag |
This may be a small nit-pick but when going through the PX4 code I encountered a line that to me has the potential to be a safety issue:
#define NAN_VALUE (0.0f/0.0f)
https://github.com/PX4/Firmware/blob/master/src/modules/px4iofirmware/mixer.cpp#L69
Here a NAN is created by dividing by zero, however this is not guaranteed to create a NAN and is undefined behaviour, as the standard states
C++11 5.6.4 - The binary / operator yields the quotient, and the binary % operator yields the remainder from the division of the first expression by the second. If the second operand of / or % is zero the behavior is undefined.
This could become an issue as this value is used to prevent the motor turning on when the system is disarmed
https://github.com/PX4/Firmware/blob/master/src/modules/px4iofirmware/mixer.cpp#L482
While unlikely, if a compiler were to set this value to a finite number it would still be compliant with the C++ standard but would result in motors running when the system is disarmed.
This is not an issue if IEEE754 floating point numbers are used as there 0.0f/0.0f is explicitly defined as NAN, however unless I missed it the only check performed for this is in the libuavcan module and it is not always enabled.
A possible solution would be a compile time assert on
std::numeric_limits<float>::is_iec559
. It would also make sense to me to define NAN_VALUE asstd::numeric_limits<float>::quiet_NaN()
The text was updated successfully, but these errors were encountered: