Skip to content

Reject unequal infinities in approximate floating-point comparisons #555

Closed

Description

@LunaStev

After the exact-equality and NaN checks, approx_eq_f32/f64 computes abs(a-b) <= max(abs(a),abs(b))*relative_tolerance. Comparing positive infinity with 1.0 using a finite positive relative tolerance makes both sides infinite, so the result is true. Opposite infinities have the same problem. The early exact-equality check only handles equal infinities.

Overflow in the difference or scaled tolerance also needs consideration for extreme finite operands.

Code evidence:

Acceptance:

  • Reject unequal non-finite operands after retaining the existing equal-value behavior.
  • Cover equal/opposite infinities, infinity versus finite values, NaNs and signed zero for both float widths.
  • Avoid false positives caused solely by overflow in intermediate finite comparisons.
  • State and test handling of negative/NaN/infinite tolerances without silently broadening the comparison.

Audit status: static source inspection against canonical master ea74c2dafc31da876e5561f2d176ba719f5a0458 on 2026-09-10. No compiler build, test execution, implementation change or local reproduction was performed for this report. The examples describe the source-derived behavior to verify when implementing the fix.

Activity

  1. added
    bug
    help wanted
    on Sep 10, 2026
  2. added a commit that references this issue on Sep 16, 2026
    451cc7a
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

    bughelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions