From 313d7d84bcfe086201640d23b449b77bdc08b135 Mon Sep 17 00:00:00 2001 From: mtarik34b Date: Tue, 15 Apr 2025 05:00:36 +0200 Subject: [PATCH 1/2] Ensure NaN != any_float_value evaluates to true for constant NaN values --- src/exact_value.cpp | 2 +- .../test_5004_nan_constant_comparison.odin | 56 ++++++++++++------- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/exact_value.cpp b/src/exact_value.cpp index f4439688c..e7981a978 100644 --- a/src/exact_value.cpp +++ b/src/exact_value.cpp @@ -955,7 +955,7 @@ gb_internal bool compare_exact_values(TokenKind op, ExactValue x, ExactValue y) f64 a = x.value_float; f64 b = y.value_float; if (isnan(a) || isnan(b)) { - return false; // Fixes #5004 + return op == Token_NotEq; // Fixes #5004 } switch (op) { diff --git a/tests/internal/test_5004_nan_constant_comparison.odin b/tests/internal/test_5004_nan_constant_comparison.odin index 2fbefb2b1..4eb3163a8 100644 --- a/tests/internal/test_5004_nan_constant_comparison.odin +++ b/tests/internal/test_5004_nan_constant_comparison.odin @@ -4,30 +4,44 @@ import "core:testing" @(test) compare_constant_nans_f32 :: proc(t: ^testing.T) { - NaN :: f32(0h7fc0_0000) - NaN2 :: f32(0h7fc0_0001) + NaN :: f32(0h7fc0_0000) + NaN2 :: f32(0h7fc0_0001) + Inf :: f32(0h7F80_0000) + Neg_Inf :: f32(0hFF80_0000) - testing.expect_value(t, NaN == NaN, false) - testing.expect_value(t, NaN == NaN2, false) - testing.expect_value(t, NaN != NaN, false) - testing.expect_value(t, NaN != NaN2, false) - testing.expect_value(t, NaN < NaN, false) - testing.expect_value(t, NaN <= NaN, false) - testing.expect_value(t, NaN > NaN, false) - testing.expect_value(t, NaN >= NaN, false) + testing.expect_value(t, NaN == NaN, false) + testing.expect_value(t, NaN == NaN2, false) + testing.expect_value(t, NaN != 0, true) + testing.expect_value(t, NaN != 5, true) + testing.expect_value(t, NaN != -5, true) + testing.expect_value(t, NaN != NaN, true) + testing.expect_value(t, NaN != NaN2, true) + testing.expect_value(t, NaN != Inf, true) + testing.expect_value(t, NaN != Neg_Inf, true) + testing.expect_value(t, NaN < NaN, false) + testing.expect_value(t, NaN <= NaN, false) + testing.expect_value(t, NaN > NaN, false) + testing.expect_value(t, NaN >= NaN, false) } @(test) compare_constant_nans_f64 :: proc(t: ^testing.T) { - NaN :: f64(0h7fff_0000_0000_0000) - NaN2 :: f64(0h7fff_0000_0000_0001) + NaN :: f64(0h7fff_0000_0000_0000) + NaN2 :: f64(0h7fff_0000_0000_0001) + Inf :: f64(0h7FF0_0000_0000_0000) + Neg_Inf :: f64(0hFFF0_0000_0000_0000) - testing.expect_value(t, NaN == NaN, false) - testing.expect_value(t, NaN == NaN2, false) - testing.expect_value(t, NaN != NaN, false) - testing.expect_value(t, NaN != NaN2, false) - testing.expect_value(t, NaN < NaN, false) - testing.expect_value(t, NaN <= NaN, false) - testing.expect_value(t, NaN > NaN, false) - testing.expect_value(t, NaN >= NaN, false) -} \ No newline at end of file + testing.expect_value(t, NaN == NaN, false) + testing.expect_value(t, NaN == NaN2, false) + testing.expect_value(t, NaN != 0, true) + testing.expect_value(t, NaN != 5, true) + testing.expect_value(t, NaN != -5, true) + testing.expect_value(t, NaN != NaN, true) + testing.expect_value(t, NaN != NaN2, true) + testing.expect_value(t, NaN != Inf, true) + testing.expect_value(t, NaN != Neg_Inf, true) + testing.expect_value(t, NaN < NaN, false) + testing.expect_value(t, NaN <= NaN, false) + testing.expect_value(t, NaN > NaN, false) + testing.expect_value(t, NaN >= NaN, false) +} From 1d2adbb3c6a756f7f289b5bba71aea459318b813 Mon Sep 17 00:00:00 2001 From: mtarik34b Date: Tue, 15 Apr 2025 05:26:36 +0200 Subject: [PATCH 2/2] Remove reference to git issue --- src/exact_value.cpp | 2 +- ...nstant_comparison.odin => test_nan_constant_comparison.odin} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename tests/internal/{test_5004_nan_constant_comparison.odin => test_nan_constant_comparison.odin} (100%) diff --git a/src/exact_value.cpp b/src/exact_value.cpp index e7981a978..37751c8f1 100644 --- a/src/exact_value.cpp +++ b/src/exact_value.cpp @@ -955,7 +955,7 @@ gb_internal bool compare_exact_values(TokenKind op, ExactValue x, ExactValue y) f64 a = x.value_float; f64 b = y.value_float; if (isnan(a) || isnan(b)) { - return op == Token_NotEq; // Fixes #5004 + return op == Token_NotEq; } switch (op) { diff --git a/tests/internal/test_5004_nan_constant_comparison.odin b/tests/internal/test_nan_constant_comparison.odin similarity index 100% rename from tests/internal/test_5004_nan_constant_comparison.odin rename to tests/internal/test_nan_constant_comparison.odin