TermCalc
A command line calculator for macOS.
TermCalc is an interactive command line calculator.
TermCalc is written in Swift and is currently available only for macOS.
Usage
Run termcalc help
to view the application's command line help:
Usage: termcalc [OPTIONS] [FLAGS] TermCalc is a command line calculator. All operations are performed using IEEE 7542008 64bit floats. Options: e, eval <str> Evaluate an expression and print the result. p, precision <int> Set the decimal precision of the output (default: 9). Flags: h, help Print this help text and exit. v, version Print the application's version number and exit.
Input
All numbers are stored and all mathematical operations are performed using 64bit floats. Numbers can be entered in any of the following formats:
123 123.456 0.123 .123
Exponential notation is also supported:
1.23e4 ⟶ 1.23 * 10 ^ 4 ⟶ 12300 1.23e4 ⟶ 1.23 * 10 ^ 4 ⟶ 0.000123
Binary, octal, decimal, and hexadecimal integer literals can be entered using a leading zero and letter prefix as below:
0b101 ⟶ 5 0o101 ⟶ 65 0d101 ⟶ 101 0x101 ⟶ 257
Operators
The following mathematical operators are supported:
+ addition  subtraction * multiplication / division % remainder ^ power ! factorial
Expressions can be nested in brackets to override the standard precedence rules, e.g (3 + 4) * 5
.
Variables
Variables are created by assigning to a name:
foo = 2 + 3
Variable names can contain letters, underscores, and numbers, but must begin with either a letter or an underscore.
The following compound assignment operators are available for use with variables: +=
, =
, *=
, /=
, %=
, ^=
. The expression:
foo += 1
is equivalent to
foo = foo + 1
Automatic Variables
The result of each evaluated expression is assigned to an automatic numbered variable: $1
, $2
, $3
, etc. (This name is displayed beside the result.)
The result of the last expression is always available via the automatic variable $
.
The mathematical constants pi
and e
are also available as preallocated variables.
Functions

Angles
deg(x) Convert x in radians to degrees. rad(x) Convert x in degrees to radians.

Trig
cos(x) Cosine of x; x in radians. sin(x) Sine of x; x in radians. tan(x) Tangent of x; x in radians. cosd(x) Cosine of x; x in degrees. sind(x) Sine of x; x in degrees. tand(x) Tangent of x; x in degrees.
Aliases with an explicit r
forradians suffix are also available: cosr
, sinr
, tanr
.

Inverse Trig
arccos(x) Inverse cosine of x; result in radians. arcsin(x) Inverse sine of x; result in radians. arctan(x) Inverse tangent of x; result in radians. arctan(x,y) Inverse tangent of y/x; result in radians, sign determined by the quadrant of (x,y). arccosd(x) Inverse cosine of x; result in degrees. arcsind(x) Inverse sine of x; result in degrees. arctand(x) Inverse tangent of x; result in degrees. arctand(x,y) Inverse tangent of y/x; result in degrees, sign determined by the quadrant of (x,y).
Aliases with an explicit r
forradians suffix are also available: arccosr
, arcsinr
, arctanr
.
Longform (arccos
) and shortform (acos
) aliases are available for each function.

Roots
cbrt(x) Cube root of x. root(n,x) Principal nth root of x. sqrt(x) Square root of x.

Logs
ln(x) Natural log of x. log(b,x) Baseb log of x. log2(x) Base2 log of x. log10(x) Base10 log of x.
Keyboard Shortcuts
Standard lineediting keyboard shortcuts are supported:
CtrlA Move the cursor to the beginning of the line. CtrlB Move the cursor backwards. CtrlC Exit the application. CtrlD Delete the character at the cursor position. CtrlE Move the cursor to the end of the line. CtrlF Move the cursor forwards. CtrlH Delete the character to the left of the cursor. CtrlK Delete all characters to the right of the cursor. CtrlL Clear the screen. CtrlU Delete all characters to the left of the cursor. CtrlW Delete the previous word. CtrlN Scroll to the next history entry. CtrlP Scroll to the previous history entry.
The up and down arrow keys can also be used to scroll backwards and forwards through history entries.