tcalc - Man Page
The terminal calculator
Synopsis
tcalc [Options] [file-name]
Description
The terminal calculator is a small and helpful program to help users of the GNU/Linux terminal do calculations simply and quickly. The formula to be calculated can be fed to tcalc through the command line. Alternatively, tcalc can be run with no formula and then the free mode is started, in which the calculator will wait for user input, do the necessary calculations and print out the result, and the cycle will repeat until the user enters 'q' or 'quit'.
The calculator works with the decimal, hexadecimal, octal, and binary number systems. It automatically identifies hex numbers if entered with a preceding "0x" or "0X", octal by preceding the number with a zero, binaries by preceding the number with 'b' and decimals by absence of all of the above. Alternatively, the user can indicate the type of input by setting the 'format' argument (See below).
Math functions defined are:
---------------------------
acos(x) Arc cosine of X
asin(x) Arc sine of X
atan(x) Arc tangent of X
atan2(y, x) Arc tangent of Y/X
cos(x) Cosine of X
sin(x) Sine of X
tan(x) Tangent of X
cosh(x) Hyperbolic cosine of X
sinh(x) Hyperbolic sine of X
tanh(x) Hyperbolic tangent of X
acosh(x) Hyperbolic arc cosine of X
asinh(x) Hyperbolic arc sine of X
atanh(x) Hyperbolic arc tangent of X
exp(x) Exponential function of X
log(x) Natural logarithm of X
log10(x) Base-ten logarithm of X
pow(x, y) X to the power Y
sqrt(x) Square root of X
cbrt(x) Cube root of X
ceil(x) Smallest integral value not less than X
floor(x) Largest integer not greater than X
fabs(x) Absolute value of X
round(x) Round X to nearest integral value, rounding halfway cases away
from zero
trunc(x) Round X to the integral value in floating-point format nearest
but not larger in magnitude
These functions can be called within a formula. to have a printout of the above list, use the "-m" or "--math" flags (see below).
The free mode:
--------------
If you start tcalc with no command line formula and no input file, this will invoke the free mode. You will see a '>' prompt indicating this mode. Enter your formulas one by one, ending each one with an ENTER, and tcalc will process the formula and output the result. You can enter other commands like
User-defined functions:
-----------------------
To define a user function, invoke tcalc with no formulas or input files (you can pass arguments like 'output' or 'decimal'), and then enter at the prompt:
> func your-function-name(list of arguments)
The prompt will change to '->' indicating you are in function definition mode. To exit this mode, type 'q' or 'quit'. Function names are currently limited to ten characters length. If you don't want to pass arguments to the function, ignore the list of arguments and the braces, just type 'func your-function-name' and press enter. Of course you will substitute 'your-function-name' with the actual name of the function!.
If defining functions in files, you should enclose the function body with curly braces, as:
func myfunc
{
statement-1
statement-2
...
}
other statements...
You can also define variables inside functions. By default, variables are initiated for the number of arguments you specify in the function declaration. If you need to declare other variables, use the 'var' command from the free mode or from inside a formula file. Note that variable names are strictly composed of lower-case latin letters "a"-"z", and must not start with a "b" (as tcalc uses this letter to identify binary numbers!).
Input files:
------------
The calculator also supports input through pretyped files. Use the '-i' or function definitions and formulas to be calculated. The tcalc will process the file and output the results. Files can contain comments. Commented line is defined as a line that starts with a hash (#). Tcalc will ignore any lines in which the hash appears. A sample file is installed with the package in the If you intend to pass your input file to the calculator through redirection (i.e. 'tcalc < test' if your file name is 'test') you should end your file with 'end' or 'quit' so the calculator will know where the input stops, otherwise it will enter an infinite loop, repeating the last command for ever!.
Options
- Formula
Formula to be calculated. Examples:
5+4
0xff*0x23
b111-b01
7*0xf
(6+5)*7
... and so on
- -c, --convert n
Convert n to the output format specified by '-o' below, or to decimal if no format is specified
- -d, --decimal n
How many digits are shown to the right of the decimal point
- -f, --format n
Input format, possible values are:
* binary (b)
* hex (x)
* decimal (d)
* octal (o)
Input format is usually automatically identified. This feature is provided only for convenience.- -h, --help
Print command line help
- -i, --input file-name
Name of file containing formulas (under development)
- -m, --math
Print a list of math functions
- -o, --output n
Output format, possible values are:
* binary (b)
* hex (x)
* decimal (d)
* octal (o)
* all formats (a)
Default output format is decimal, which will be used if '-o' option is not used.- -q, --quiet
Minimize output messages
- -t, --table n
Print the multiplication table of number 'n'
- -v, --version
Display program version and exit
Files
file-name The name of the file containing formulas to be calculated.
Todo
- Testing and debugging
See Also
info tcalc
Author
Mohammed Isam <mohammed_isam1984@yahoo.com>