Skip to content
Merged
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
2 changes: 1 addition & 1 deletion AngouriMath/Core/FromString/Lexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace AngouriMath.Core.FromString
{
internal class TokenList : List<Token>
{
public void Add(Token a)
public new void Add(Token a)
{
if (!string.IsNullOrEmpty(a.Value))
{
Expand Down
6 changes: 5 additions & 1 deletion AngouriMath/Core/Sys/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ namespace AngouriMath
/// Every node, expression, or number is an Entity
/// However, you cannot create an instance of this class
/// </summary>
#pragma warning disable CS0660
#pragma warning disable CS0661
public abstract partial class Entity
#pragma warning restore CS0661
#pragma warning restore CS0660
{
public string Name { get; set; }
public bool IsLeaf { get => Children.Count == 0; }
Expand Down Expand Up @@ -93,7 +97,7 @@ public NumberEntity(Number value) : base(value.ToString()) {
Value = value;
}
public Number Value { get; internal set; }
public string Name { get => Value.ToString(); }
public new string Name { get => Value.ToString(); }
public static implicit operator NumberEntity(int num) => new NumberEntity(num);
public static implicit operator NumberEntity(Number num) => new NumberEntity(num);
}
Expand Down
4 changes: 4 additions & 0 deletions AngouriMath/Core/Sys/Number.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

namespace AngouriMath.Core
{
#pragma warning disable CS0660
#pragma warning disable CS0661
public class Number
#pragma warning restore CS0660
#pragma warning restore CS0661
{
/// <summary>
/// To get real value of the number
Expand Down
2 changes: 1 addition & 1 deletion AngouriMath/Functions/Algebra/NewtonSolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private Number NewtonIter(FastExpression f, FastExpression df, VariableEntity x,
{
value = value - f.Substitute(value) / df.Substitute(value);
}
catch(MathSException e)
catch(MathSException)
{
throw new MathSException("Two or more variables in SolveNt is forbidden");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ private void InnerCompile(InstructionSet instructions, string[] variables, Dicti
}
public class FastExpression
{
private Stack stack;
private Stack<Number> stack;
private InstructionSet instructions;
private int varCount;
internal FastExpression(InstructionSet instructions, int varCount)
{
this.varCount = varCount;
stack = new Stack(instructions.Count);
stack = new Stack<Number>(instructions.Count);
this.instructions = instructions;
}

Expand Down Expand Up @@ -108,9 +108,9 @@ public Number Substitute(params Number[] variables)
break;
}
}
if (stack.Depth != 1)
if (stack.Count != 1)
throw new Exception("Stack error");
var res = stack.Last;
var res = stack.Peek();
stack.Clear();
return res;
}
Expand Down
56 changes: 31 additions & 25 deletions AngouriMath/Functions/Evaluation/Compilation/MathFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal static class CompiledMathFunctions
{ "logf", 7 },
};

internal delegate void CompiledFunction(Stack stack);
internal delegate void CompiledFunction(Stack<Number> stack);
internal static CompiledFunction[] functions =
new CompiledFunction[]
{
Expand All @@ -35,45 +35,51 @@ internal static class CompiledMathFunctions

internal static Number[] buffer = new Number[10];

internal static void Sumf(Stack stack)
internal static void Sumf(Stack<Number> stack)
{
stack.Pop(2, buffer);
stack.Push(buffer[0] + buffer[1]);
Number n1 = stack.Pop();
Number n2 = stack.Pop();
stack.Push(n1 + n2);
}
internal static void Minusf(Stack stack)
internal static void Minusf(Stack<Number> stack)
{
stack.Pop(2, buffer);
stack.Push(buffer[0] - buffer[1]);
Number n1 = stack.Pop();
Number n2 = stack.Pop();
stack.Push(n1 - n2);
}
internal static void Mulf(Stack stack)
internal static void Mulf(Stack<Number> stack)
{
stack.Pop(2, buffer);
stack.Push(buffer[0] * buffer[1]);
Number n1 = stack.Pop();
Number n2 = stack.Pop();
stack.Push(n1 * n2);
}
internal static void Divf(Stack stack)
internal static void Divf(Stack<Number> stack)
{
stack.Pop(2, buffer);
stack.Push(buffer[0] / buffer[1]);
Number n1 = stack.Pop();
Number n2 = stack.Pop();
stack.Push(n1 / n2);
}
internal static void Powf(Stack stack)
internal static void Powf(Stack<Number> stack)
{
stack.Pop(2, buffer);
stack.Push(Number.Pow(buffer[0], buffer[1]));
Number n1 = stack.Pop();
Number n2 = stack.Pop();
stack.Push(Number.Pow(n1, n2));
}
internal static void Sinf(Stack stack)
internal static void Sinf(Stack<Number> stack)
{
stack.Pop(1, buffer);
stack.Push(Number.Sin(buffer[0]));
Number n = stack.Pop();
stack.Push(Number.Sin(n));
}
internal static void Cosf(Stack stack)
internal static void Cosf(Stack<Number> stack)
{
stack.Pop(1, buffer);
stack.Push(Number.Cos(buffer[0]));
Number n = stack.Pop();
stack.Push(Number.Cos(n));
}
internal static void Logf(Stack stack)
internal static void Logf(Stack<Number> stack)
{
stack.Pop(2, buffer);
stack.Push(Number.Log(buffer[0], buffer[1]));
Number n1 = stack.Pop();
Number n2 = stack.Pop();
stack.Push(Number.Log(n1, n2));
}
}
}
34 changes: 0 additions & 34 deletions AngouriMath/Functions/Evaluation/Compilation/Stack.cs

This file was deleted.