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

False positive in MISRA C++ 2008 Rule 6–2–2 #9

Open
d3lta-v opened this issue Oct 16, 2024 · 0 comments
Open

False positive in MISRA C++ 2008 Rule 6–2–2 #9

d3lta-v opened this issue Oct 16, 2024 · 0 comments

Comments

@d3lta-v
Copy link

d3lta-v commented Oct 16, 2024

Describe the bug
The bug is found in the checker for MISRA C++ 2008 Rule 6–2–2, which states that floating point numbers should not be checked for equality or inequality. The program seems to apply this rule to any floating point comparison, not just floating point equality or inequality checks (i.e. == or !=).

For example, the following snippet of code (with a method that's actually recommended within the MISRA C++ standard to do floating point equality tests) is

bool relativelyEqual(float a, float b, float epsilon = std::numeric_limits<float>::epsilon())
{
    return std::abs(a - b) <= epsilon * std::max(std::abs(a), std::abs(b));
}

This is flagged by Analyze as a rule 6-2-2 violation, possibly due to the use of <= symbol. Other simple comparisons such as if (a > 0.0) where a is a float or double also results in a 6-2-2 violation.

To Reproduce
Steps to reproduce the behavior:

  1. Analyze any code with a floating point comparison as stated above
  2. The software will report this as a 6-2-2 violation

Expected behavior
The violation should not be flagged by the software.

Desktop (please complete the following information):

  • OS: Fedora 40 running Analyze through Podman
  • Version: latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant