-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,4 +115,14 @@ public void Foo(IEnumerable enumerable, IEnumerable<object> genericEnumerable) | |
|
||
public void OfType() => OfType(); | ||
} | ||
|
||
// https://github.com/SonarSource/sonar-dotnet/issues/9498 | ||
public class Repro_9498 | ||
{ | ||
void Sample() | ||
{ | ||
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 commentThe 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 commentThe 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. 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 commentThe 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.
We do not fix casts, only
.Cast<T>
andas T
expressions.