Skip to content

Commit d1172ce

Browse files
committed
BasicArithmeticalExpression: Added additional logic to handle cases such as -sin(5).
1 parent 114c79f commit d1172ce

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

MathParser/MathParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ private decimal BasicArithmeticalExpression(List<string> tokens)
527527
var op = tokens[0];
528528

529529
if (op == "-" || op == "+")
530-
return decimal.Parse((op == "+" ? "" : "-") + tokens[1], CultureInfo);
530+
return decimal.Parse((op == "+" ? "" : (tokens[1].Substring(0,1) == "-" ? "" : "-" ) ) + tokens[1], CultureInfo);
531531

532532
return OperatorAction[op](0, decimal.Parse(tokens[1], CultureInfo));
533533
}

MathParser/UnitTest/BugFixes.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
3+
4+
namespace UnitTest
5+
{
6+
[TestClass]
7+
public class BugFixes
8+
{
9+
[TestMethod]
10+
public void UnaryOperators()
11+
{
12+
var mp = new Mathos.Parser.MathParser();
13+
var result = mp.Parse("-sin(5)");
14+
}
15+
}
16+
}

MathParser/UnitTest/UnitTest.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
<ItemGroup>
6060
<Compile Include="UnitTest1.cs" />
6161
<Compile Include="Properties\AssemblyInfo.cs" />
62+
<Compile Include="BugFixes.cs" />
6263
</ItemGroup>
6364
<ItemGroup>
6465
<ProjectReference Include="..\MathParser.csproj">

0 commit comments

Comments
 (0)