Added bracket support
This commit is contained in:
parent
a7ef4b0af7
commit
a9be1638c3
8 changed files with 164 additions and 72 deletions
56
Common/CalculatorExtensions.cs
Normal file
56
Common/CalculatorExtensions.cs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
namespace calculator.Common;
|
||||
|
||||
public static class CalculatorExtensions
|
||||
{
|
||||
public static int Precedence(this Operation op)
|
||||
{
|
||||
switch (op)
|
||||
{
|
||||
case Operation.Add:
|
||||
case Operation.Sub:
|
||||
return 1;
|
||||
case Operation.Mul:
|
||||
case Operation.Div:
|
||||
case Operation.Factorial:
|
||||
return 2;
|
||||
case Operation.PowY:
|
||||
case Operation.SqrtY:
|
||||
return 3;
|
||||
case Operation.Cube:
|
||||
case Operation.Pow:
|
||||
case Operation.Sqrt:
|
||||
case Operation.CubeRoot:
|
||||
case Operation.Square:
|
||||
case Operation.Log:
|
||||
case Operation.Ln:
|
||||
case Operation.Exp:
|
||||
case Operation.Inv:
|
||||
case Operation.Pi:
|
||||
case Operation.OneDiv:
|
||||
case Operation.Mod:
|
||||
case Operation.Neg:
|
||||
case Operation.Percent:
|
||||
case Operation.Sinh:
|
||||
case Operation.Sin:
|
||||
case Operation.Cosh:
|
||||
case Operation.Cos:
|
||||
case Operation.Tanh:
|
||||
case Operation.Tan:
|
||||
return 4;
|
||||
default:
|
||||
case Operation.OpenBracket:
|
||||
case Operation.CloseBracket:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsBigger(this Operation a, Operation b)
|
||||
{
|
||||
return Precedence(a) > Precedence(b);
|
||||
}
|
||||
|
||||
public static bool IsLowerOrEqual(this Operation a, Operation b)
|
||||
{
|
||||
return Precedence(a) <= Precedence(b);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue