项目作者: s4p0

项目描述 :
Equation calculator: Parse expressions and calculate its result.
高级语言: C#
项目地址: git://github.com/s4p0/Equation.git
创建时间: 2017-02-12T21:55:45Z
项目社区:https://github.com/s4p0/Equation

开源协议:MIT License

下载


Equation

Parse and calculate math expressions with constants and function.

A .NET (Mono compatible) C# implementation of Shunting-yard Algorithm

This solution supports:

  • use of unary operations;
  • prioritizations using parenthesis;
  • easy to create new constant support (list below);
  • easy to create new function support (list below);
  • and, all done converting it to postfix format.

Functions supported:

  • basic math operations [+-*/];
  • sqrt;
  • power;
  • and, it is easy to implement others.

Constants supported:

  • E;
  • PI;
  • RAD;
  • and, it is easy to implement others.

Use:

  1. ExpressionCalculator calc = new ExpressionCalculator();
  2. double result;
  3. var expression = "3 + 4 * 2 / ( 1 - 5 ) ^ 2 ^ 3";
  4. if (calc.Solve(expression, out result))
  5. {
  6. Console.WriteLine("Final result: {0}", result);
  7. }

output: Final result: 3.0001220703125

ps.: it does not implement a full parenthesis check or any syntax analyze.


Proudly done using Visual Studio for Mac (preview 3)