Skip to content

Commit cd816f4

Browse files
committed
ExprEngine: fix code for float comparisons
1 parent b55c587 commit cd816f4

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

‎lib/exprengine.cpp‎

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,24 @@ bool ExprEngine::BinOpResult::isIntValueInRange(int value) const
496496
return result; \
497497
}
498498

499+
#define BINARY_RELATIONAL_COMPARISON(OP) \
500+
if (binop == #OP) { \
501+
struct ExprEngine::BinOpResult::IntOrFloatValue result(lhs); \
502+
if (lhs.isFloat()) \
503+
{ result.setIntValue(lhs.floatValue OP (rhs.isFloat() ? rhs.floatValue : rhs.intValue)); } \
504+
else if (rhs.isFloat()) \
505+
{ result.setIntValue(lhs.intValue OP rhs.floatValue); } \
506+
else { result.setIntValue(lhs.intValue OP rhs.intValue); } \
507+
return result; \
508+
}
509+
510+
#define BINARY_EQ_COMPARISON(OP) \
511+
if (binop == #OP && !lhs.isFloat() && !rhs.isFloat()) { \
512+
struct ExprEngine::BinOpResult::IntOrFloatValue result; \
513+
result.setIntValue(lhs.intValue OP rhs.intValue); \
514+
return result; \
515+
}
516+
499517
#define BINARY_INT_OP(OP) \
500518
if (binop == #OP) { \
501519
struct ExprEngine::BinOpResult::IntOrFloatValue result; \
@@ -527,12 +545,12 @@ ExprEngine::BinOpResult::IntOrFloatValue ExprEngine::BinOpResult::evaluate(int t
527545
BINARY_INT_OP(^)
528546
BINARY_INT_OP(<<)
529547
BINARY_INT_OP(>>)
530-
BINARY_INT_OP(==)
531-
BINARY_INT_OP(!=)
532-
BINARY_OP(>=)
533-
BINARY_OP(>)
534-
BINARY_OP(<=)
535-
BINARY_OP(<)
548+
BINARY_EQ_COMPARISON(==)
549+
BINARY_EQ_COMPARISON(!=)
550+
BINARY_RELATIONAL_COMPARISON(>=)
551+
BINARY_RELATIONAL_COMPARISON(>)
552+
BINARY_RELATIONAL_COMPARISON(<=)
553+
BINARY_RELATIONAL_COMPARISON(<)
536554

537555
if (binop == "%" && rhs.intValue != 0) {
538556
struct ExprEngine::BinOpResult::IntOrFloatValue result;

0 commit comments

Comments
 (0)