diff options
| author | kcbanner <kcbanner@gmail.com> | 2024-11-06 19:33:52 -0500 |
|---|---|---|
| committer | kcbanner <kcbanner@gmail.com> | 2025-03-03 15:35:07 -0500 |
| commit | 981f84157ce9e37cdc7ea96ea736808b1273142e (patch) | |
| tree | 664763af25eda9e0c9beeddd5eb7a21086205dbf /src | |
| parent | edabcf61927f9699f9b869f304e9aed97f2c4a47 (diff) | |
| download | zig-981f84157ce9e37cdc7ea96ea736808b1273142e.tar.gz zig-981f84157ce9e37cdc7ea96ea736808b1273142e.zip | |
Value: fix comparison of NaN in compareHeteroAdvanaced
Sema: fix equality comparison of signed zeroes and NaN in compareScalar
tests: add test coverage for vector float comparisons
Diffstat (limited to 'src')
| -rw-r--r-- | src/Sema.zig | 5 | ||||
| -rw-r--r-- | src/Value.zig | 2 |
2 files changed, 7 insertions, 0 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index 9e729a17ea..5982024d89 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -38137,6 +38137,11 @@ fn compareScalar( const pt = sema.pt; const coerced_lhs = try pt.getCoerced(lhs, ty); const coerced_rhs = try pt.getCoerced(rhs, ty); + + // Equality comparisons of signed zero and NaN need to use floating point semantics + if (coerced_lhs.isFloat(pt.zcu) or coerced_rhs.isFloat(pt.zcu)) + return Value.compareHeteroSema(coerced_lhs, op, coerced_rhs, pt); + switch (op) { .eq => return sema.valuesEqual(coerced_lhs, coerced_rhs, ty), .neq => return !(try sema.valuesEqual(coerced_lhs, coerced_rhs, ty)), diff --git a/src/Value.zig b/src/Value.zig index be2c73c3e9..40e5331c4e 100644 --- a/src/Value.zig +++ b/src/Value.zig @@ -1132,6 +1132,8 @@ pub fn compareHeteroAdvanced( else => {}, } } + + if (lhs.isNan(zcu) or rhs.isNan(zcu)) return op == .neq; return (try orderAdvanced(lhs, rhs, strat, zcu, tid)).compare(op); } |
