termc is a calculator for the command line. The goal of this project is to provide an easy-to-use and intuitive command line calculator with a basic range of functions. It supports the basic operations ("+", "-", "*", "/", "%" and "^") as well as the following built-in mathematical functions:
- cos
- sin
- tan
- cot
- acos
- asin
- atan
- acot
- cosh
- sinh
- tanh
- coth
- acosh
- asinh
- atanh
- acoth
- ln
- exp
- sqrt
- pow (e.g. "pow(5, 2)" = 25)
- root (e.g. "root(4, 2)" = 2)
- im
- re
Futhermore, the following built-in constants are supported:
- e
- pi
- i (the imaginary unit)
termc supports complex numbers. Example:
$ termc
>>> sin(5+3i)
ans = -9.654125476854839+2.841692295606352i
termc supports scientific notation. Example:
$ termc
>>> 25E-3
ans = 0.025
termc supports input and output in decimal, binary, octal and hexadecimal system. Furthermore, termc supports output in the IEEE754 binary format. Example:
$ termc
>>> 0b101.11
ans = 5.75
>>> format hex
>>> ans
ans = 0x5.c
>>> 0o753.457
ans = 0x1eb.978
>>> format ieee754
>>> ans
ans = 0b100000001111110101110010111100000000000000000000000000000000000
>>> format dec
>>> ans
ans = 491.591796875
termc supports the definition of custom constants. Example:
$ termc
>>> custom_constant = 5*pi/4
>>> cos(custom_constant)
ans = -0.7071067811865477
termc supports the definition of custom functions. Example:
$ termc
>>> f(a, b, c) = a + b - c
>>> f(5, 3-2i, sin(pi/2))
ans = 7-2i
termc supports the serialization and deserialization of all custom functions and constants. Therefore, all definitions can be saved to a file. Example:
$ termc
>>> f(x) = x^2
>>> c = 79.882
>>> save /home/kantic/termc_context.json
>>> exit
$ termc
>>> load /home/kantic/termc_context.json
>>> f(c)
ans = 6381.133924000001
>>> ...
termc remembers the user inputs in a session. Thus, the user is able to quickly get previous inputs by using the up and down arrow-keys.
termc prints helpful error messages if the user made some mistakes in his input. Example:
$ termc
>>> pow(2.7, 3
Error: Expected symbol ")".
pow(2.7, 3
^~~~
>>> cis(pi)
Error: Expected function or operation.
cis(pi)
^~~~ Found: cis
termc compilation has been tested on both linux (Debian 8) and Windows (Windows 10). All unix-like operating systems on which rust is available should work, too!
termc supports two different modes of operation.
In this mode, the user can pass mathematical expressions as command line arguments to termc.
$ termc 1+2 5*7 "cos(pi)"
3;35;-1
For this mode, no additional command line arguments are passed to the call of termc. It will then start in interactive mode.
$ termc
>>> 1+2
ans = 3
>>> 5*7
ans = 35
...
GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 A copy of the license can be found in the root directory of this repository.