Skip to content

Commit

Permalink
Fix comparisons with Undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
fintarin committed Feb 19, 2024
1 parent 7697483 commit 9adc5a9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
9 changes: 6 additions & 3 deletions src/fintamath/expressions/binary/CompExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,13 @@ std::shared_ptr<IFunction> CompExpression::getOppositeFunction(const IFunction &
}

ArgumentPtr CompExpression::constSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs) {
if (is<Undefined>(lhs) || is<Undefined>(rhs)) {
// TODO: return LogicUndefined
return makeExpr(func, Undefined(), Undefined());
}

if ((is<ComplexInf>(lhs) && containsInfinity(rhs)) ||
(is<ComplexInf>(rhs) && containsInfinity(lhs)) ||
is<Undefined>(lhs) ||
is<Undefined>(rhs)) {
(is<ComplexInf>(rhs) && containsInfinity(lhs))) {

return {};
}
Expand Down
21 changes: 10 additions & 11 deletions tests/src/overall/simplify/SimplifyInfinityTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,25 +687,24 @@ TEST(SimplifyInfinityTests, simplifyTest) {
EXPECT_EQ(Expression("sin(Undefined)").toString(),
"Undefined");

// TODO: support LogicUndefined
EXPECT_EQ(Expression("Undefined = Undefined").toString(),
"Undefined = 0");
"Undefined = Undefined");
EXPECT_EQ(Expression("0/0 = 0/0").toString(),
"Undefined = 0");
"Undefined = Undefined");
EXPECT_EQ(Expression("(sin(x)^2 + cos(x)^2 - 1)/0 = 0/(sin(x)^2 + cos(x)^2 - 1)").toString(),
"Undefined = 0");
"Undefined = Undefined");
EXPECT_EQ(Expression("Inf - Inf = 0").toString(),
"Undefined = 0");
"Undefined = Undefined");
EXPECT_EQ(Expression("Inf - Inf = 0 | a").toString(),
"a | Undefined = 0");
"a | Undefined = Undefined");
EXPECT_EQ(Expression("Undefined < Undefined").toString(),
"Undefined < 0");
"Undefined < Undefined");
EXPECT_EQ(Expression("0/0 < 0/0").toString(),
"Undefined < 0");
"Undefined < Undefined");
EXPECT_EQ(Expression("(sin(x)^2 + cos(x)^2 - 1)/0 < 0/(sin(x)^2 + cos(x)^2 - 1)").toString(),
"Undefined < 0");
"Undefined < Undefined");
EXPECT_EQ(Expression("Inf - Inf < 0").toString(),
"Undefined < 0");
"Undefined < Undefined");
EXPECT_EQ(Expression("Inf - Inf < 0 | a").toString(),
"a | Undefined < 0");
"a | Undefined < Undefined");
}

0 comments on commit 9adc5a9

Please sign in to comment.