Skip to content

Commit 9c58754

Browse files
committed
Fixed mixing of parameters and variables.
Calculated Node included to compilation unit.
1 parent 95281a8 commit 9c58754

File tree

8 files changed

+107
-53
lines changed

8 files changed

+107
-53
lines changed

MathFunctions.GUI/frmMain.Designer.cs

Lines changed: 91 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MathFunctions.GUI/frmMain.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private void btnCalculate_Click(object sender, EventArgs e)
130130
MathFunc derivativeFunc = null;
131131
try
132132
{
133-
derivativeFunc = new MathFunc(tbInput.Text).GetDerivative();
133+
derivativeFunc = new MathFunc(tbInput.Text, tbVar.Text).GetDerivative();
134134
tbDerivative.Text = derivativeFunc.ToString();
135135
}
136136
catch (Exception ex)
@@ -168,5 +168,10 @@ private void btnSave_Click(object sender, EventArgs e)
168168
Assembly.Finalize(Path.GetDirectoryName(saveFileDialog1.FileName), Path.GetFileName(saveFileDialog1.FileName));
169169
}
170170
}
171+
172+
private void tbResultExpression_Click(object sender, EventArgs e)
173+
{
174+
(sender as TextBox).SelectAll();
175+
}
171176
}
172177
}

MathFunctions.GUI/frmMain.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,6 @@ log(f(x), g(x))' = g'(x)/(g(x)*ln(f(x))) - (f'(x)*ln(g(x)))/(f(x)*ln(f(x))^2);
158158
<value>17, 17</value>
159159
</metadata>
160160
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
161-
<value>56</value>
161+
<value>107</value>
162162
</metadata>
163163
</root>

MathFunctions.v11.suo

-7.5 KB
Binary file not shown.

MathFunctions/MathExprParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ private void CreateNewObject(Reduction r)
265265

266266
case ProductionIndex.Statement:
267267
// <Statement> ::= <Expression>
268-
Funcs.Push(new MathFunc(Nodes.Pop()));
268+
Funcs.Push(new MathFunc(Nodes.Pop(), null, Parameters.Select(p => p.Value)));
269269
break;
270270

271271
case ProductionIndex.Expression:

MathFunctions/MathFunc.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ protected void ConstToVar(MathFuncNode node)
280280
for (int i = 0; i < node.Childs.Count; i++)
281281
if (node.Childs[i] == null || node.Childs[i].Name == Variable.Name)
282282
node.Childs[i] = Variable;
283+
else if (node.Childs[i].Type == MathNodeType.Variable)
284+
node.Childs[i] = new ConstNode(node.Childs[i].Name);
283285
else
284286
ConstToVar(node.Childs[i]);
285287
}

MathFunctions/MathFuncCompilation.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ private void EmitNode(MathFuncNode node, bool abs = false)
197197
{
198198
switch (node.Type)
199199
{
200+
case MathNodeType.Calculated:
201+
IlInstructions.Add(new OpCodeArg(OpCodes.Ldc_R8,
202+
abs ? Math.Abs(((CalculatedNode)node).Value) : ((CalculatedNode)node).Value));
203+
break;
200204
case MathNodeType.Value:
201205
IlInstructions.Add(new OpCodeArg(OpCodes.Ldc_R8,
202206
abs ? Math.Abs(((ValueNode)node).Value.ToDouble()) : ((ValueNode)node).Value.ToDouble()));
@@ -237,7 +241,7 @@ private bool EmitFunc(FuncNode funcNode, bool abs = false)
237241
case KnownFuncType.Mult:
238242
return EmitMultFunc(funcNode);
239243
case KnownFuncType.Div:
240-
throw new NotSupportedException("replace devision with inversation and multiplication");
244+
throw new NotSupportedException("replace division with inversation and multiplication");
241245
case KnownFuncType.Neg:
242246
return EmitNegFunc(funcNode, abs);
243247
case KnownFuncType.Exp:

MathFunctions/MathFuncDerivative.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public MathFunc GetDerivative()
1212
{
1313
var result = Simplify(GetDerivative(Root));
1414
result.Sort();
15-
return new MathFunc(result);
15+
return new MathFunc(result, Variable, Parameters.Select(p => p.Value));
1616
}
1717

1818
#region Helpers

0 commit comments

Comments
 (0)