Skip to main content

a simple cli RPN calculator written in Python

Project description

installation

Requires the latest stable Python version.

pip install kalk

Usage

After installation run kalk from your terminal.

In RPN syntax one would first enter the operands and then the operator:

>>> 1
1
>>> 2
2
>>> +
3

You may also enter the operands and the operator in one line, just use space to separate them:

>>> 41 1 +
42

(tip: the space is not needed when the syntax is not ambiguous.)

Kalk tries to follow Python’s syntax. Similar to Python, ** is the power operator and ^ is bitwise XOR:

>>> 3 3 **
27
>>> 3 3 ^
0

Kalk ignores , (thousands separator) within numbers.

>>> 1,234 1 +
1,235

Most of the functions defined in Python’s math and statistics modules are supported.

>>> 6 lgamma
4.787491742782047

and many more.

You can even do datetime and timedelta calculations:

>>> "2023-03-22" dt
2023-03-22 00:00:00
>>> 2 days 3 hours +
2 days, 3:00:00
>>> -
2023-03-19 21:00:00

Start a substack (a list) with a [ and end it with a ]. Some functions require lists as argument. For example to calculate the distance between two points or sum of some numbers:

>>> [2 -1] [-2 2] dist
5.0
>>> [0 0 0] [1 1 1] dist
1.7320508075688772
>>> [1 1 1] sum
3

Handy operators:

  • <> swaps the place of the last two values in the stack.

  • c clears the stack

  • cp copies the last result to clipboard.

  • del deletes the last n + 1 values from from the stack with n being the last value in the stack.

  • e adds Euler’s number to the stack

  • pi adds the pi constant to the stack

  • pst pastes the contents of clipboard and evaluates it.

  • a the last answer

  • s prints the stack

  • sto stores the value before the last in storage using the last stack value as the key.

  • rcl recalls the value in storage using the last stack value as the key.

  • h prints a list of all operators. (still needs lots of refinements.)

  • ? prints the docstring of the operator given as a string. For example "<>" ? will print the help string on swap. Note that not all functions have documentation yet.

  • ctrl+c (KeyboardInterrupt) will cancel the current input.

  • exit will quit the program.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kalk-0.19.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kalk-0.19.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file kalk-0.19.0.tar.gz.

File metadata

  • Download URL: kalk-0.19.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.12

File hashes

Hashes for kalk-0.19.0.tar.gz
Algorithm Hash digest
SHA256 97a928b55f1aebb63508047e4b5b99e5f9e87630aba75c774db44d01086b5800
MD5 b868475831d94a59e077a0a0b5af892e
BLAKE2b-256 c32d53197ba4bfff98629205d3866032f77920aaa3933ff458fb59bdffa6947d

See more details on using hashes here.

File details

Details for the file kalk-0.19.0-py3-none-any.whl.

File metadata

  • Download URL: kalk-0.19.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.12

File hashes

Hashes for kalk-0.19.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3dd733d4402aa11abfc24ecc7ebbd936f52f06e28952cb2679c3a6a369f1ccd5
MD5 955943652a33cbc8d23c38bbfa74bafe
BLAKE2b-256 ed88c09c8f0cf3e89ae2ffe8ff952204b7975a51619bfb9eeec7af5cfc4c7130

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page