Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Raccoon Calculator - Python RPN calculator with bases support

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.rst
Octocat-spinner-32 rcpy
Octocat-spinner-32 rcpy.1
README.rst

RCPY - Racoon Calculator in Python

SYNOPSIS

rcpy echo 10 20 + p | rcpy

DESCRIPTION

RCPY is a simple reverse-polish notation calculator written in python. Its purpose was to add thing I felt were missing in dc(1) that I need in my daily usage of a calculator.

It supports decimal, hexadecimal, binary as well as binary operation on these values.

STACK HANDLING

pop:     print and remove the value from stack

dump:    dump the current stack content

d:       duplicate the top value of the stack

print:   print the value on top of stack
p:       same as `print`

swap:    swap the last 2 values on top of stack
r:       same as `swap`

clear:   empty the stack
c:       same as clear

Current  mode  is shown in the prompt, the used mode won't neither the values
already in stack nor the inputed values. If you add 0x42 to your stack while
being in bin mode, the stack will still con‐ tains 0x42 but if you do an
operation, the output will be in the chosen mode.

hex:     switch output of operations to hexadecimal

bin:     switch output of operations to binary

dec:     switch output of operations to decimal

conv:    convert value on top of the stack to the selected mode, this command won't work on floating values

int:     convert a floating value to an integer

GENERIC COMMANDS

quit:    quit RC
q:       same as `quit`

OPERATIONS

+        Addition
-        Substraction
*        Multiplication
x        Multiplication
/        Division
%        Modulo
^        Power
v        Square root

All operation pop the two top values, and replace them by the result of the operation in the stack.

BINARY OPERATIONS

&        Logical and
|        Logical or
xor      Logical xor (^ being used for power)
<<       Shift to left
>>       Shift to right

All binary operation pop the two top values, and replace them by the result of the operation in the stack.

MACROS

Rcpy can handle some macros, the handling of this is quite basic and may leave room for improvements.

m:       register macro, m id op1 op2...  This can be used at any given time, but the macro will store all commands following the id until the end of the line.

@:       call back a macro '@ id'

EXAMPLE

Sample session of RC:

[dec] rcpy> 10 20 30
[dec] rcpy> dump
10
20
30
[dec] rcpy> + d
10
50
[dec] rcpy> hex
[hex] rcpy> + p
0x3c
[hex] rcpy> bin
[bin] rcpy> conv
0x3c -> 0b111100
[bin] rcpy> dec
[dec] rcpy> 7 / p
8
[dec] rcpy> 22 / p
0.363636363636
[dec] rcpy> 10.7 + p
11.0636363636
[dec] rcpy> 1 4 << 1 8 << | p
272
[dec] rcpy> hex
[hex] rcpy> conv
272 -> 0x110
[dec] rcpy> m a / 1000 * p
[dec] rcpy> 3.95 300 @ a
13.166666666666666
[dec] rcpy> 2.68 200 @ a
13.4
Something went wrong with that request. Please try again.