You can do a lot of things inside a Terminal window, even use a calculator. These are some calculator programs.

Table of Contents

Bash arithmetic expansion

You can perform arithmetic calculations without any external program, just englobe the operation with a $ and double parentheses. You can also use expr.

echo $((5+8))
expr 5 + 8

wcalc

You can run wcalc and a mathematical expression (use single quotes when adding the expression):

$ wcalc 'log(8)'
 = 0.90309

Or you can only run wcalc and you will enter into interactive mode.

$ wcalc
Enter an expression to evaluate, q to quit, or ? for help:
-> 

Type wcalc -P and the number of decimals displayed for the results.

$ wcalc -P20 pi
 = 3.14159265358979323846

Some examples of using wcalc:

-> 2*3
 = 6
-> sqrt(8)
 = 2.82843
-> ln 5
 = 1.60944

bc

bc allows to add calculations on a file and run bc <file>. It also has an interactive mode and it can get the operations from stdin:

$ echo "3.3+5.6" | bc
8.9
$ bc
bc 1.07.1
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006, 2008, 2012-2017 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'. 

  • You can exit from this mode by typing q.

bc -l includes a math library with several basic functions included, like l(x) for the natural logarithm of ‘x’, or s(x)for the sine of ‘x’ (‘x’ is in radians).

bc has some predefined variables. One of them is ‘scale’ and it means the number of decimals displayed. You can modify it by typing scale=<number> inside bc interactive mode.

scale=2
1/3
.33

Some examples of using bc:

4*(3+5)
32
3^2
9
# from decimal to binary
$ echo "obase=2; 3" | bc
11