rpn
is a simple but useful, CLI
RPN calculator for
Linux. rpn
is written in Go and is statically compiled, requiring no external
libraries. Installation is as simple as running one command and should work on
any Linux distribution.
This is a work in progress, but rpn
already supports a rich set of operations
and should be useful for daily work.
I've been using RPN calculators for a long time and the lack of a simple and
convenient CLI version (think bc
, but using RPN) frustrated me. I've used
dc
many times, but it has some quirks that quickly stand in the way of
productivity, like having to print the results of the stack every single time,
no editing in the command-line, etc.
Looking around the Debian repos and Github revealed some possible alternatives, but they also come with their own set of inconveniences, like:
- Requiring a GUI.
- Requiring the installation of many dependencies (npm, Java runtime, etc).
- Not allowing editing of the command-line, or recall of a previous line.
- Using a TUI (and making editing more complicated).
- Buggy or incomplete implementations.
- Too complex.
The idea of rpn
is to be simple and functional enough to be your daily driver
RPN calculator. :)
To download and install automatically (under /usr/local/bin
), just run:
curl -s \
'https://raw.githubusercontent.com/marcopaganini/rpn/master/install.sh' |
sudo sh -s -- marcopaganini/rpn
This assumes you have root equivalence using sudo
and will possibly require you
to enter your password.
To download and install under another directory (for example, $HOME/.local/bin
), run:
curl -s \
'https://raw.githubusercontent.com/marcopaganini/rpn/master/install.sh' |
sh -s -- marcopaganini/rpn "$HOME/.local/bin"
Note that sudo
is not required on the second command as the installation directory
is under your home. Whatever location you choose, make sure your PATH environment
variable contains that location.
RPN is available on homebrew. To install, use:
brew tap marcopaganini/homebrew-tap
brew install rpn
Just navigate to the releases page and download the desired
version. Unpack the tar file into /usr/local/bin
and run a chmod 755 /usr/local/bin/rpn
. If typing rpn
doesn't work after that, make sure
/usr/local/bin
is in your PATH. In some distros you may need to create
/usr/local/bin
first.
If you have go installed, just run:
go install github.com/marcopaganini/rpn@latest
This projects uses the excellent decimal math library, by Eric Lagergren, so it inherits its strengths and limitations:
- RPN uses General Decimal Arithmetic.
- Internally, we use the IEEE 754R Decimal128 format, with a precision a maximum
scale of
10^128
. - Maximum precision is 34 digits.
- When operating on non-decimal numbers, input is truncated to a
uint64
(maximum =2^64
). - We currently trim trailing fractional zeroes. This means that, for example,
1.23 + 1.27
will give2.5
as a result, and not2.50
. There are valid applications that require the full precision and we may add an option for that if enough people need it. n / 0 == Infinity
0 / 0 == Nan
- Anything above
10^128 == +Infinity
There are many other calculators for Linux, and some of them supporting RPN. This is a list of a few that support RPN:
- dc: The
venerable
dc
calculator. One of the oldest Unix programs. Readily available in most distributions. dc is somewhat quirky and does not support many operations, but uses arbitrary precision math and supports truly gigantic numbers. - dcim: An improved version of
dc
. - orpie: A Curses-based RPN calculator (TUI).
- qalculate: A very complete calculator with CLI, GTK, and QT versions. Focus is mostly on the UI part. The author doesn't seem to use RPN so the RPN mode is a bit rough around the edges.
Feel free to open issues, send ideas and PRs.