Skip to content

Commit 2aed8b5

Browse files
committed
fix #198: Fix comparison of 0 with NaN
1 parent 6192d53 commit 2aed8b5

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

include/scratchcpp/value.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,12 @@ class LIBSCRATCHCPP_EXPORT Value
553553
return doubleToString(d1) == v2.toString();
554554
else
555555
return stringsEqual(v1.toUtf16(), v2.toUtf16());
556-
} else if (v1.isNumber() || v2.isNumber())
557-
return v1.toDouble() == v2.toDouble();
558-
else if (v1.isBool() || v2.isBool())
556+
} else if (v1.isNumber() || v2.isNumber()) {
557+
if (static_cast<int>(v1.m_type) < 0 || static_cast<int>(v2.m_type) < 0)
558+
return false;
559+
else
560+
return v1.toDouble() == v2.toDouble();
561+
} else if (v1.isBool() || v2.isBool())
559562
return ((v1.m_type != Type::NaN && v2.m_type != Type::NaN) && (v1.toBool() == v2.toBool()));
560563
else
561564
return false;

test/scratch_classes/value_test.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,9 +1873,8 @@ TEST(ValueTest, EqualityOperators)
18731873
ASSERT_FALSE(v1 == v5);
18741874
ASSERT_TRUE(v1 != v5);
18751875

1876-
// TODO: Enable this after #198 is fixed
1877-
/*ASSERT_FALSE(v2 == v5);
1878-
ASSERT_TRUE(v2 != v5);*/
1876+
ASSERT_FALSE(v2 == v5);
1877+
ASSERT_TRUE(v2 != v5);
18791878
}
18801879

18811880
{
@@ -2042,8 +2041,7 @@ TEST(ValueTest, EqualityOperators)
20422041
ASSERT_FALSE(v3 == v7);
20432042
ASSERT_TRUE(v3 != v7);
20442043

2045-
// TODO: Enable this after #198 is fixed
2046-
/*ASSERT_FALSE(v4 == v7);
2047-
ASSERT_TRUE(v4 != v7);*/
2044+
ASSERT_FALSE(v4 == v7);
2045+
ASSERT_TRUE(v4 != v7);
20482046
}
20492047
}

0 commit comments

Comments
 (0)