diff --git a/src/scripting/codegeneration/codegen.cpp b/src/scripting/codegeneration/codegen.cpp index f78dcdff6c..a9c5d40e74 100644 --- a/src/scripting/codegeneration/codegen.cpp +++ b/src/scripting/codegeneration/codegen.cpp @@ -2525,6 +2525,7 @@ FxExpression *FxCompareEq::Resolve(FCompileContext& ctx) return NULL; } + if (Operator == TK_ApproxEq && ValueType->GetRegType() != REGT_FLOAT) Operator = TK_Eq; if (left->isConstant() && right->isConstant()) { int v; @@ -2533,7 +2534,7 @@ FxExpression *FxCompareEq::Resolve(FCompileContext& ctx) { double v1 = static_cast(left)->GetValue().GetFloat(); double v2 = static_cast(right)->GetValue().GetFloat(); - v = Operator == TK_Eq? v1 == v2 : v1 != v2; + v = Operator == TK_Eq? v1 == v2 : Operator == TK_Neq? v1 != v2 : fabs(v1-v2) < VM_EPSILON; } else { @@ -2588,7 +2589,7 @@ ExpEmit FxCompareEq::Emit(VMFunctionBuilder *build) // See FxUnaryNotBoolean for comments, since it's the same thing. build->Emit(OP_LI, to.RegNum, 0, 0); - build->Emit(instr, Operator != TK_Eq, op1.RegNum, op2.RegNum); + build->Emit(instr, Operator == TK_ApproxEq? CMP_APPROX : Operator != TK_Eq, op1.RegNum, op2.RegNum); build->Emit(OP_JMP, 1); build->Emit(OP_LI, to.RegNum, 1); return to; diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index 06c08f6811..bf3d14d06e 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -2535,6 +2535,7 @@ FxExpression *ZCCCompiler::ConvertNode(ZCC_TreeNode *ast) case PEX_EQEQ: case PEX_NEQ: + case PEX_APREQ: return new FxCompareEq(tok, left, right); case PEX_Assign: @@ -2563,8 +2564,6 @@ FxExpression *ZCCCompiler::ConvertNode(ZCC_TreeNode *ast) // todo: These do not have representations in DECORATE and no implementation exists yet. case PEX_Concat: case PEX_Is: - // more esoteric operators - case PEX_APREQ: // vector operations will be done later. case PEX_CrossProduct: