-
Notifications
You must be signed in to change notification settings - Fork 226
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
Reproducer for S1905 FP: Floating point arithmetic #9520
Conversation
void Sample() | ||
{ | ||
float x = 3.14f; | ||
float res = 1 / (float)(x * 2); // Fixed |
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.
We do not fix casts, only .Cast<T>
and as T
expressions.
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.
For the reproducer, the result of the calculation does not change. To properly document this, we need to find an example where the change is visible.
As a side note, I do not know how we would implement a fix for this.
float x = 3.14f; | ||
float res = 1 / (float)(x * 2); // Noncompliant FP |
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.
Can you find an example where the precision change is visible?
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.
I don't think it matters, as the solution would probably be what Jared suggested on the post.
Which is to be conservative and raise only in very few circumstances, when the RHS is a variable.
Even more conservative, we could also not raise on floating point arithmetic at all.
What do you think?
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.
I think we should document a case where this is actually an FP and think about a concrete solution later (or consider it a niche case and ignore it).
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.
See the comment above
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.
LGTM!
Quality Gate passed for 'Sonar .NET Java Plugin'Issues Measures |
Quality Gate passed for 'SonarAnalyzer for .NET'Issues Measures |
Repro for #9498