Code Monkey home page Code Monkey logo

rpn-calc's Introduction

Reverse Polish Notation

The objective in this project is to build a complete, polished, but small product: A reverse polish notation calculator in the style of a unix command line tool.

ToDo

  • Pipelining feature
  • Major refactoring of parser and run commands methods
  • Fix display_mode switching
  • Conditional operator :?:
  • Networking operators

Requirements

python-3.6+ and pip

Installation

Use the python package manager tool pip to install package rpn-calc from source repository

pip install git+https://github.com/karimov/rpn-cal.git

Usage

As a standard unix-like command line tools, the rpn-calc supports different modes of user experience as well.

  rpn                          Launch in interactive mode
  rpn [expression]             Evaluate a one-line expression

RC FILE

  rpn will execute the contents of ~/.rpnrc at startup if it exists.

EXAMPLES

  rpn 1 2 + 3 + 4 + 5 +              => 15
  rpn pi cos                         => -1.0
  rpn                                => interactive mode

For example, a programmer working on a low level project might expect binary and hex input/output:

$ rpn
> bin
> 0xaa55
0b1010101001010101 > 2 |
0b1010101001010111 > 1 ~ &
0b1010101001010110 >

And someone interested in factorials may expect more than the usual level of precision:

$ rpn
> 50 fact
30414093201713378043612608166064768844377641568960512000000000000 >

Command Set Help

As of current version of rpn-calc supports following set of functionality.

Arithmetic Operators

  +          Add
  -          Subtract
  *          Multiply
  /          Divide
  cla        Clear the stack and variables
  clr        Clear the stack
  clv        Clear the variables
  !          Boolean NOT
  !=         Not equal to
  %          Modulus
  ++         Increment
  --         Decrement

Bitwise Operators

  &          Bitwise AND
  |          Bitwise OR
  ^          Bitwise XOR
  ~          Bitwise NOT
  <<         Bitwise shift left
  >>         Bitwise shift right

Boolean Operators

  &&         Boolean AND
  ||         Boolean OR
  ^^         Boolean XOR

Comparison Operators

  <          Less than
  <=         Less than or equal to
  ==         Equal to
  >          Greater than
  >=         Greater than or equal to

Trigonometric Functions

  acos       Arc Cosine
  asin       Arc Sine
  atan       Arc Tangent
  cos        Cosine
  cosh       Hyperbolic Cosine
  sin        Sine
  sinh       Hyperbolic Sine
  tanh       Hyperbolic tangent

Numeric Utilities

  ceil       Ceiling
  floor      Floor
  round      Round
  ip         Integer part
  fp         Floating part
  sign       Push -1, 0, or 0 depending on the sign
  abs        Absolute value
  max        Max
  min        Min

Display Modes

  hex        Switch display mode to hexadecimal
  dec        Switch display mode to decimal (default)
  bin        Switch display mode to binary
  oct        Switch display mode to octal

Constants

  e          Push e
  pi         Push Pi
  rand       Generate a random number

Mathematic Functions

  exp        Exponentiation
  fact       Factorial
  sqrt       Square Root
  ln         Natural Logarithm
  log        Logarithm
  pow        Raise a number to a power

Networking

  hnl        Host to network long
  hns        Host to network short
  nhl        Network to host long
  nhs        Network to host short

Stack Manipulation

  pick       Pick the -n'th item from the stack
  repeat     Repeat an operation n times, e.g. '3 repeat +'
  depth      Push the current stack depth
  drop       Drops the top item from the stack
  dropn      Drops n items from the stack
  dup        Duplicates the top stack item
  dupn       Duplicates the top n stack items in order
  roll       Roll the stack upwards by n
  rolld      Roll the stack downwards by n
  stack      Toggles stack display from horizontal to vertical
  swap       Swap the top 2 stack items

Macros and Variables

  macro      Defines a macro, e.g. 'macro kib 1024 *'
  x=         Assigns a variable, e.g. '1024 x='

Other

  help       Print the help message
  exit       Exit the calculator

rpn-calc's People

Contributors

karimov avatar

Stargazers

 avatar  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.