-
Notifications
You must be signed in to change notification settings - Fork 18k
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
Replace fabsF macro with std::abs call to avoid having float / double mismatch warnings #28642
Conversation
…oat / double mismatch warnings AP_Math: Replace fabsF macro with std::abs call in templates to avoid having float / double mismatch warnings
Perhaps fabsF should be removed everywhere and replaced by std::abs? |
@@ -733,7 +733,7 @@ void ModeGuided::pos_control_run() | |||
|
|||
float pos_offset_z_buffer = 0.0; // Vertical buffer size in m | |||
if (guided_pos_terrain_alt) { | |||
pos_offset_z_buffer = MIN(copter.wp_nav->get_terrain_margin() * 100.0, 0.5 * fabsF(guided_pos_target_cm.z)); | |||
pos_offset_z_buffer = MIN(copter.wp_nav->get_terrain_margin() * 100.0, 0.5 * std::abs(guided_pos_target_cm.z)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the variable is a float, will it promote to double by making this change? That would slow things a lot on older boards
we could add a float cast to the float version of fabsF() |
The float versions are here: https://en.cppreference.com/w/cpp/numeric/math/fabs |
But if you want to avoid using std library then let me try with the float cast |
I thought this was the point - it's a feature not a bug. We want the right version that has been configured, using abs removes the type-safety |
Closing this PR. Going with #28897 instead with the cast method instead of the switch to std::abs proposed in this PR. |
The fabsF macro is defined as either the float version or double version in ftype.h depending on HAL_WITH_EKF_DOUBLE. If it is defined as the float version and a double is used as the argument then we get a compiler warning in the Qurt build. If those are replaced with std:abs calls then that clears up the warnings since it is overloaded for both floats and doubles.