-
Notifications
You must be signed in to change notification settings - Fork 27
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
MathOnFloatProcessor and CastArithmeticOperandProcessor can produce non-compilable output #570
Comments
According to discussion during meeting, we don't attempt to repair if we can tell before hand that there will be a compile error. |
Even if the end result is the same, I guess one could still argue that the code is less efficient, less readable and a potentially important warning is suppressed. There is also two roundings going on so I think the end result could actually have worse accuracy. Even though this paper claims that it is safe for addition, subtraction, multiplication, division and square root. Wouldn't it be a better idea to skip the repair if the result must be cast to float? Or would that make the processor more complex? |
During a meeting today, we agreed that we do not attempt to repair these warnings if we can determine that doing so will cause a compile error. This amounts to implementing |
To be clear, we don't cast to float. |
Cool, this is achieved with Spoon? |
Yeah, the analysis is implemented with Spoon. The related methods can be found in We need to define for example |
This is rather tricky. Sorald is technically doing exactly what Sonar says, namely casting to double. It's just that in a few cases, that's not the right thing to do (even though Sonar says so). For example:
The problem is of course that the right hand side is now a double, but you can't assign a double to a float due to lossy conversion. Sonar only says to cast to double, so from that perspective, Sorald is doing the right thing.
It's the same case for all compilation failures. If the variables are changed to
double
instead offloat
, the compile error disappears. My only suggestion for solving this is that, in the case that whatever reads the result of the expression expects a float, then cast the entire expression to float. E.g. like so:It makes for some really ugly code, though. @fermadeiral thoughts? Any other ideas?
Originally posted by @slarse in #569 (comment)
The text was updated successfully, but these errors were encountered: