Skip to content

Commit

Permalink
Fixed arity constant bug
Browse files Browse the repository at this point in the history
Fixes #9
  • Loading branch information
65001 committed Apr 15, 2019
1 parent 1e5995f commit 1676870
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
Binary file modified AbMath/AbMath.dll
Binary file not shown.
4 changes: 2 additions & 2 deletions AbMath/Calculator/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -558,15 +558,15 @@ private void DefaultFunctions()
{
Arguments = 0,
MinArguments = 0,
MaxArguments = 1,
MaxArguments = 0,
Compute = DoFunctions.Pi
});

AddFunction("e", new Function
{
Arguments = 0,
MinArguments = 0,
MaxArguments = 1,
MaxArguments = 0,
Compute = DoFunctions.EContstant
});
#endregion
Expand Down
2 changes: 1 addition & 1 deletion AbMath/Calculator/PostFix/PostFix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private double[] GetArguments(int argCount)

if (_stack.Count < argCount )
{
throw new InvalidOperationException($"Syntax Error! Asked for {argCount} but only had {_stack.Count} in Stack");
throw new InvalidOperationException($"Syntax Error! Asked for {argCount} but only had {_stack.Count} in Stack.");
}

for (int i = argCount; i > 0; i--)
Expand Down
27 changes: 26 additions & 1 deletion AbMath/Calculator/Shunt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,35 @@ void Dump()
else
{
var output = _operator.Pop();

if (output.IsFunction() && _arity.Count > 0)
{
output.Arguments = _arity.Pop();
}

_output.Enqueue(output);
}
}

//This in effect suppresses any Arity Exceptions!!
//This assigns arity values to the output stream
for (int i = 0; i < _output.Count; i++)
{
Token token = _output.Dequeue();

if (token.IsFunction() && _arity.Count > 0)
{
Function func = _dataStore.Functions[token.Value];
//Constants cannot have an arity assigned to them.
if (func.MaxArguments != 0)
{
token.Arguments = _arity.Pop();
}
}

_output.Enqueue( token );
}

//This in effect suppresses any Arity Exceptions!!
while ( _arity.Count > 0)
{
for (int i = 0; i < (_output.Count - 1); i++)
Expand All @@ -459,6 +483,7 @@ void Dump()

_output.Enqueue(foo);
}

}

void Write(string message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ public void SqrtReduction()
Assert.AreEqual(-1, math.Compute());
}

[Test]
public void VardiacImplicitMultiplication()
{
test.SetEquation("3sum(1,4,5)");
Expand All @@ -328,6 +329,16 @@ public void VardiacImplicitMultiplication()
Assert.AreEqual(30, math.Compute());
}

[Test]
public void VardiacImplicitMultiplication2()
{
test.SetEquation("sum(1,4,5)3");
test.Compute();

PostFix math = new PostFix(test);
Assert.AreEqual(30, math.Compute());
}

public void Write(object sender,string Event)
{
Console.WriteLine(Event);
Expand Down

0 comments on commit 1676870

Please sign in to comment.