Skip to content

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

Description

@d3lta-v

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

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions