Skip to content

Use unordered inequality for floating-point not-equal comparisons #682

Closed

Description

@LunaStev

Problem

The LLVM backend lowers floating-point != with FloatPredicate::ONE in all three numeric paths: float/float, int/float, and float/int. ONE requires ordered operands, so a quiet NaN makes the comparison false.

Equality already uses ordered equality. As a result, n == n and n != n are both false for NaN, while !(n == n) is true. The != operator does not behave as the negation of equality for these operands.

Code references:

Source-derived regression

Save as nan_inequality.wave:

import("std::math::float")::{nan_f32, nan_f64};

fun main() -> i32 {
    var n64: f64 = nan_f64();
    var n32: f32 = nan_f32();
    var equal: bool = n64 == n64;
    var unequal: bool = n64 != n64;
    var negated_equal: bool = !(n64 == n64);
    var unequal32: bool = n32 != n32;

    if (equal) {
        return 1;
    }
    if (!unequal) {
        return 2;
    }
    if (!negated_equal) {
        return 3;
    }
    if (!unequal32) {
        return 4;
    }
    return 0;
}

Expected: exit 0, with equality false and both inequality forms true. The current ONE selection predicts a false result for each NaN inequality. This Wave program has not yet been compiled or executed for this report.

A separately authored LLVM predicate test produced OEQ=false, ONE=false, and UNE=true for quiet NaN at both float widths and at O0/O2. That tests the selected LLVM operations, not the complete Wave pipeline.

Expected behavior and scope

Use unordered-or-not-equal semantics for floating-point !=, such as FloatPredicate::UNE, consistently across the three numeric paths. Keep equality and ordered relational comparisons unchanged.

This does not change integer/pointer comparisons, introduce approximate equality, or redefine mixed numeric promotion. Tests must use ordinary floating-point settings, not options that explicitly permit assuming NaNs do not occur.

Completion criteria

  • wavec check nan_inequality.wave accepts the source, and the compiled program exits 0 at unoptimized and optimized settings.
  • Actual Wave-generated IR uses unordered inequality for float/float, int/float, and float/int != paths.
  • Cover quiet NaN on the left, right, and both sides for f32 and f64.
  • Use typed integer variables in mixed tests so literal contextualization cannot bypass the mixed lowering branches.
  • Preserve results for equal/unequal finite values, equal/opposite infinities, and positive/negative zero.
  • Verify a != b agrees with !(a == b) for the supported comparison cases, without changing <, >, <=, or >= predicates.
  • Add focused compiler IR tests and runnable Wave cases; no new runtime helper or external math library is required.

Difficulty: easy. Related #555 concerns the standard library's approximate-comparison implementation, not the compiler's != operator.

Activity

  1. added
    bug
    good first issue
    needs testing
    on Sep 21, 2026
  2. self-assigned this
    on Sep 24, 2026
  3. added a commit that references this issue on Sep 24, 2026
    01955d7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

buggood first issueneeds testing

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions