Skip to content

DIR-4-15: Add support for fpclassify() functions. #875

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

Open
MichaelRFairhurst opened this issue Mar 25, 2025 · 0 comments
Open

DIR-4-15: Add support for fpclassify() functions. #875

MichaelRFairhurst opened this issue Mar 25, 2025 · 0 comments
Labels
Difficulty-Low A false positive or false negative report which is expected to take <1 day effort to address false positive/false negative An issue related to observed false positives or false negatives. Impact-Low

Comments

@MichaelRFairhurst
Copy link
Contributor

Affected rules

  • DIR-4-15\

Description

The first implementation of the rule handles guards of the form isinf, isnan, isfinite, iszero, etc., however, it doesn't support guards relating to fpclassify().

Example

float may_be_inf() {
  ...
  return 1.0/0.0;
}

void fpclassify_guard() {
  float x = may_be_inf();
  int y;

  // error, casting possible infinity to int
  y = x; 

  // example 1: easiest to support:
  if (fpclassify(x) != FP_INFINITE) {
    // or "fpclassify(x) == FP_NORMAL"
    y = x;
  }

  // example 2: perhaps slightly harder to support, but guards library already has infra for this:
  switch(x) {
    case FP_NORMAL:
    case FP_SUBNORMAL:
    case FP_ZERO:
      // or, "case FP_INFINITE: break; default:"
      y = x;
  }

  // example 3: this is harder to support but a common pattern:
  int cls = fpclassify(x);
  if (cls != FP_INFINITE) {
    // or "cls == FP_NORMAL || cls == FP_ZERO"
    y = x;
  }   
}
@MichaelRFairhurst MichaelRFairhurst added Difficulty-Low A false positive or false negative report which is expected to take <1 day effort to address false positive/false negative An issue related to observed false positives or false negatives. Impact-Low labels Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty-Low A false positive or false negative report which is expected to take <1 day effort to address false positive/false negative An issue related to observed false positives or false negatives. Impact-Low
Projects
None yet
Development

No branches or pull requests

1 participant