Coder Social home page Coder Social logo

rpn-calculator's Introduction

RPN Calculator

This is a simple calculator that uses the RPN (Reverse Polish Notation) method to calculate the result of an expression.

Buiding the project

To build the project, you need to run the following command:

$ make

Running the project

To run the project, you need to run the following command:

$ ./build/rpn

How to use

Operators

To use the calculator, you need to type the expression in the following format:

<value1> <value2> <operator>

Where:

  • <value1> is the first value of the expression
  • <value2> is the second value of the expression
  • <operator> is the operator that will be used to calculate the result of the expression (it can be +, -, *, ^, % or /)

Unary operators are also supported. In this case, the expression should be in the following format:

<value> <operator>

Where:

  • <value> is the value of the expression
  • <operator> is the operator that will be used to calculate the result of the expression (it can be !)

Other operators can be easily added by a plugin system. To do that, you need to create a new file in the src/operators directory and implement the Operator interface (located in the src/operators/operator_api.h file). They will be automatically loaded by the calculator from the build/plugins/operators directory.

Commands

The calculator also supports some commands that can be used to interact with it. The available commands are:

  • a, all : Prints all the values in the stack
  • p, print : Prints the stack's head
  • c, clear : Clears the stack
  • r, reverse : Reverses the stack's head
  • q, quit : Quits the calculator

Example

Here is an example of how to use the calculator:

>>> 5 5 + 2 *
>>> all
20 
>>> 0 /
Divide by 0
>>> all
20 0 
>>> clear
>>> 0 10 - !
Negative factorial
>>> clear
>>> 4294967295
Number too big
>>> -10 4294967 1000
>>> all
-10 4294967 1000 
>>> *
Integer overflow
>>> clear
>>> 2 8 ^
>>> all
256 

rpn-calculator's People

Contributors

nicolas-93 avatar

Watchers

 avatar

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.