Coder Social home page Coder Social logo

kolosovpetro / rpncalculator Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 2.0 43 KB

Reverse Polish Notation Calculator. Evaluates infix expressions.

C# 100.00%
rpn-calculator rpn-expression reverse-polish-notation infix infix-notation evaluates-infix-expressions postfix-notation postfix

rpncalculator's Introduction

RPN Calculator

Reverse Polish Notation Calculator. Evaluates infix expressions.

  • Supported operators: +, -, *, /, ^, sin, cos, tan, ln, log, sqrt, ctan, exp
  • Supported constants: e, pi

Separate each token with whitespace.

Code snippet

var infixString = "3 + 4 * 2 / ( 1 - 5 ) ^ 2 ^ 3";
Console.WriteLine(ShuntingYard.InfixToPostfixString(infixString));    // 3 4 2 * 1 5 - 2 3 ^ ^ / +
Console.WriteLine(InfixEvaluator.EvaluateInfix(infixString));    // 3,0001220703125
            
infixString = "3 + 4 ^ ( 1 / 2 )";
Console.WriteLine(ShuntingYard.InfixToPostfixString(infixString));    // 3 4 1 2 / ^ +
Console.WriteLine(InfixEvaluator.EvaluateInfix(infixString));    // 5

infixString = "10 * ( 10 + 1 ) ^ 2";
Console.WriteLine(ShuntingYard.InfixToPostfixString(infixString));    // 10 10 1 + 2 ^ *
Console.WriteLine(InfixEvaluator.EvaluateInfix(infixString));    // 1210

infixString = "1 + cos ( 1 / 2 ) + sin ( 1 / 2 )";
Console.WriteLine(ShuntingYard.InfixToPostfixString(infixString));    // 1 1 2 / cos + 1 2 / sin +
Console.WriteLine(InfixEvaluator.EvaluateInfix(infixString));    // 2,3570081004945758

infixString = "2 + ( tan ( 1 / 2 ) ) ^ 2 + cos ( 0 )";
Console.WriteLine(ShuntingYard.InfixToPostfixString(infixString));    // 2 1 2 / tan 2 ^ + 0 cos +
Console.WriteLine(InfixEvaluator.EvaluateInfix(infixString));    // 3,298446410409525
            
infixString = "2 + ln ( tan ( 1 / 2 ) ) + cos ( 0 )";
Console.WriteLine(ShuntingYard.InfixToPostfixString(infixString));    // 2 1 2 / tan ln + 0 cos +
Console.WriteLine(InfixEvaluator.EvaluateInfix(infixString));    // 2,395417554058408
            
infixString = "ln ( exp ( 2 ) )";
Console.WriteLine(ShuntingYard.InfixToPostfixString(infixString));    // 2 exp ln
Console.WriteLine(InfixEvaluator.EvaluateInfix(infixString));    // 2
            
infixString = "sqrt ( e ^ pi )";
Console.WriteLine(ShuntingYard.InfixToPostfixString(infixString));    // 2,718281828459045 3,141592653589793 ^ sqrt
Console.WriteLine(InfixEvaluator.EvaluateInfix(infixString));    // 4,810477380965351
            
infixString = "sin ( pi / 4 )";
Console.WriteLine(ShuntingYard.InfixToPostfixString(infixString));    // 3,141592653589793 4 / sin
Console.WriteLine(InfixEvaluator.EvaluateInfix(infixString));    // 0,7071067811865476

rpncalculator's People

Contributors

kolosovpetro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ghostdog02 oathx

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.