aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2025-04-15 12:29:17 +0200
committerGitHub <noreply@github.com>2025-04-15 12:29:17 +0200
commit2d5b85f9f99b505aa2e75f09d4c0d39d249cb72e (patch)
tree7ff8ea706956c11a3e29b8bebecdedf82c4ee924
parent753c3fa0a790cb6a866c63b6da4db1c0bc30acae (diff)
parent1d2adbb3c6a756f7f289b5bba71aea459318b813 (diff)
Merge pull request #5038 from mtarik34b/noteq-comparison-for-nan-must-be-true
Ensure `NaN != any_float_value` evaluates to true for constant NaN values
-rw-r--r--src/exact_value.cpp2
-rw-r--r--tests/internal/test_5004_nan_constant_comparison.odin33
-rw-r--r--tests/internal/test_nan_constant_comparison.odin47
3 files changed, 48 insertions, 34 deletions
diff --git a/src/exact_value.cpp b/src/exact_value.cpp
index f4439688c..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 false; // Fixes #5004
+ return op == Token_NotEq;
}
switch (op) {
diff --git a/tests/internal/test_5004_nan_constant_comparison.odin b/tests/internal/test_5004_nan_constant_comparison.odin
deleted file mode 100644
index 2fbefb2b1..000000000
--- a/tests/internal/test_5004_nan_constant_comparison.odin
+++ /dev/null
@@ -1,33 +0,0 @@
-package test_internal
-
-import "core:testing"
-
-@(test)
-compare_constant_nans_f32 :: proc(t: ^testing.T) {
- NaN :: f32(0h7fc0_0000)
- NaN2 :: f32(0h7fc0_0001)
-
- 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)
-}
-
-@(test)
-compare_constant_nans_f64 :: proc(t: ^testing.T) {
- NaN :: f64(0h7fff_0000_0000_0000)
- NaN2 :: f64(0h7fff_0000_0000_0001)
-
- 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
diff --git a/tests/internal/test_nan_constant_comparison.odin b/tests/internal/test_nan_constant_comparison.odin
new file mode 100644
index 000000000..4eb3163a8
--- /dev/null
+++ b/tests/internal/test_nan_constant_comparison.odin
@@ -0,0 +1,47 @@
+package test_internal
+
+import "core:testing"
+
+@(test)
+compare_constant_nans_f32 :: proc(t: ^testing.T) {
+ 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 != 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)
+ 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 != 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)
+}