Skip to content

A small rpn calculator in a style of unix command line tool.

License

Notifications You must be signed in to change notification settings

karimov/rpn-calc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A small rpn calculator in a style of unix command line tool.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages