Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,10 @@ public ExpressionBase ApplyMathematic(ExpressionBase right, MathematicOperation

case RequirementOperator.Multiply: // a * 0 => 0
case RequirementOperator.BitwiseAnd: // a & 0 => 0
return new IntegerConstantExpression(0);
if (MemoryAccessor.Field.IsFloat)
return new FloatConstantExpression(0.0f);
else
return new IntegerConstantExpression(0);

case RequirementOperator.BitwiseXor: // a ^ 0 => a
ModifyingOperator = RequirementOperator.None;
Expand All @@ -620,7 +623,11 @@ public ExpressionBase ApplyMathematic(ExpressionBase right, MathematicOperation
break;

case RequirementOperator.Modulus: // a % 1 => 0
return new IntegerConstantExpression(0);
if (!MemoryAccessor.Field.IsFloat)
return new IntegerConstantExpression(0);

// float % 1 returns the fractional part
break;
}
}

Expand Down
40 changes: 40 additions & 0 deletions Tests/Parser/Expressions/Trigger/MemoryAccessorExpressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,46 @@ public void TestBuildTrigger(string input, string expected)
ExpressionType.MemoryAccessor, "byte(0x001234) & 0x000000F7")]
[TestCase("byte(0x001234)", "&", "0x0000007F",
ExpressionType.MemoryAccessor, "byte(0x001234) & 0x0000007F")]
[TestCase("byte(0x001234)", "*", "1",
ExpressionType.MemoryAccessor, "byte(0x001234)")]
[TestCase("byte(0x001234)", "*", "0",
ExpressionType.IntegerConstant, "0")]
[TestCase("byte(0x001234)", "*", "1.0",
ExpressionType.MemoryAccessor, "byte(0x001234)")]
[TestCase("byte(0x001234)", "*", "0.0",
ExpressionType.IntegerConstant, "0")]
[TestCase("byte(0x001234)", "/", "1",
ExpressionType.MemoryAccessor, "byte(0x001234)")]
[TestCase("byte(0x001234)", "/", "0",
ExpressionType.Error, "Division by zero")]
[TestCase("byte(0x001234)", "%", "1",
ExpressionType.IntegerConstant, "0")]
[TestCase("byte(0x001234)", "%", "0",
ExpressionType.Error, "Division by zero")]
[TestCase("byte(0x001234)", "%", "1.0",
ExpressionType.IntegerConstant, "0")]
[TestCase("byte(0x001234)", "&", "0",
ExpressionType.IntegerConstant, "0")]
[TestCase("byte(0x001234)", "^", "0",
ExpressionType.MemoryAccessor, "byte(0x001234)")]
[TestCase("float(0x001234)", "*", "1.0",
ExpressionType.MemoryAccessor, "float(0x001234)")]
[TestCase("float(0x001234)", "*", "0.0",
ExpressionType.FloatConstant, "0.0")]
[TestCase("float(0x001234)", "*", "1",
ExpressionType.MemoryAccessor, "float(0x001234)")]
[TestCase("float(0x001234)", "*", "0",
ExpressionType.FloatConstant, "0.0")]
[TestCase("float(0x001234)", "/", "1.0",
ExpressionType.MemoryAccessor, "float(0x001234)")]
[TestCase("float(0x001234)", "/", "0.0",
ExpressionType.Error, "Division by zero")]
[TestCase("float(0x001234)", "%", "1.0",
ExpressionType.MemoryAccessor, "float(0x001234) % 1.0")]
[TestCase("float(0x001234)", "%", "0.0",
ExpressionType.Error, "Division by zero")]
[TestCase("float(0x001234)", "%", "1",
ExpressionType.MemoryAccessor, "float(0x001234) % 1")]
public void TestCombine(string left, string operation, string right, ExpressionType expectedType, string expected)
{
// MemoryAccessorExpression.Combine just converts to a ModifiedMemoryAccessor and
Expand Down
Loading