Skip to content
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

Stop using -fsingle-precision-constant #5620

Closed
lucasdemarchi opened this issue Jan 25, 2017 · 5 comments
Closed

Stop using -fsingle-precision-constant #5620

lucasdemarchi opened this issue Jan 25, 2017 · 5 comments

Comments

@lucasdemarchi
Copy link
Contributor

This is the usual case in which the remedy creates more problems than it's solving. By passing -fsingle-precision-constant to the compiler we make literals in the code to be interpreted as float rather than double. The problem is that there's no way to tell that a literal is in fact double so in cases in which it's needed, it's a) truncated to float and b) cause a warning of implicit float to double promotion when involved in other operations. This is what happens today on libraries/AP_Math/location.cpp.

It's also the case of least surprise in which C++ developers already expect that to be true. It's very easy to learn for those who don't know, makes our code "less special" and the warning -Wdouble-promotion is there to help mitigate the problems.

Plan to solve it:

  1. Remove that flag from the compiler
  2. Fix the warnings throughout the codebase in cases a double literal is used when it should be using a float one

With this in place we should be able to eliminate the remaining implicit float to double conversions.

@khancyr
Copy link
Contributor

khancyr commented Jan 25, 2017

nice idea ! I see those warning (mostly in gps and location). Another solution could be to make them static const double instead of define !

@lucasdemarchi
Copy link
Contributor Author

@khancyr yes, I agree. But it's just a matter of time until more appear. I don't like these surprises because we have a flag to deviate from the standard. Also, this makes the behavior different on sitl/linux than what it is on stm32 boards.

@rmackay9
Copy link
Contributor

I'll ask @CraigElder to add to the agenda for the next dev call?

@CraigElder
Copy link
Contributor

Thanks Randy. Added

@lucasdemarchi
Copy link
Contributor Author

As discussed today on the dev call feedback was that this is not desired because would need to change the codebase to add the f suffix and new people get it wrong which would cause operations on double variables rather than float.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants