cli-calc

Logo

cli-calc

test codecov Python Version

pypi github release pypi downloads

DEV

Powerful yet easy command line calculator.

$ cli-calc
hex, int, float, : INPUT
0x0, 0, 0.0, : 24 * 60
24*60
0x5a0, 1440, 1440.0, : _ * 60
1440.0*60
0x15180, 86400, 86400.0, : sin(pi / 2)
sin(pi/2)
0x1, 1, 1.0, : q
$

Why cli-calc, and not plain python?

$ python
Python 3.8.5 (default, Aug  2 2020, 16:00:15)
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 2**10
1024
>>> _ / 10
102.4
>>> import math
>>> math.pi
3.141592653589793
>>> math.sin(math.pi / 2)
1.0
>>> exit()

Please note: Using plain python at the command line already does provide a pretty decent calculator: Python as a Calculator.

Not all is straight forward. For example, if you want to calculate sin(pi/2):

But there must be a better way! And there is…

cli-calc

Batteries included:

More examples

$ cli-calc
hex, int, float, : INPUT
0x0, 0, 0.0, : cos(pi/2)
cos(pi/2)
0x0, 0, 6.123233995736766e-17, : 0xFF ^ 0b10
0xFF^0b10
0xfd, 253, 253.0, : 2**8-1
2**8-1
0xff, 255, 255.0, : log(e)
log(e)
0x1, 1, 1.0, : comb(49,6)
comb(49,6)
0xd56048, 13983816, 13983816.0, : factorial(42)
factorial(42)
0x3c1581d491b28f523c23abdf35b689c908000000000, 1405006117752879898543142606244511569936384000000000, 1.40500611775288e+51, : random()
random()
0x0, 0, 0.24958817003921918, : cmath.phase(complex(-1.0, 0.0))
cmath.phase(complex(-1.0,0.0))
0x3, 3, 3.141592653589793, : q
$

Included Math Libraries

Ready to use out of the box:

Calling Help

cli-calc
h
--------------------------------------------------

    cli-calc 0.3.1: Powerful yet easy command line calculator.

    INPUT:
    "q" for quit, "h" for help

    "_" for last float value
    "_int_" for last int value

    "sin(pi/2)" for sinus, ...

    "pi", "tau" and "e" for pi, tau and Euler

    "+f" to add display for fraction, "-f" to suppress display for fraction
        Other letters are:
        he(x), (o)ctal, (b)inary, (i)nteger,
        (f)raction, (t)ruth, i(e)ee, ieee_bi(n), f(r)om_ieee
        "float" is always visible

    Also try "cos(pi/2)", "0xFF ^ 0b10", "2**8-1", "factorial(42)", "help(math)"

    See https://docs.python.org/3/library/math.html, use without "math."
        https://www.w3schools.com/python/python_operators.asp
        https://github.com/cruisen/cli-calc

    (c) 2022-2022 Nikolai von Krusenstiern, License: MIT

--------------------------------------------------
hex, int, float, : INPUT

Installation

pip install cli-calc

Configuration

For convenience, add a shell script in ~/bin:

cd ~/bin
vi cli-calc

with the following lines:

Note: Please adjust the path!

path=~/path/to/your/cli-calc/
cd $path
python3 -m cli_calc

Make it executable:

chmod a+x cli-calc

then use it anywhere. :-)

echo "7+8" | cli-calc
cat foo.bar | cli-calc
cli-calc

Warning

Pull Request

PR’s are Welcome!

License

MIT

Author: Nikolai von Krusenstiern

Credits

This project was generated with wemake-python-package. Current template version is: d06993f12e3ffad79652a2aec86189dee92d94dd. See what is updated since then.