The Wayback Machine - http://web.archive.org/web/20150906043252/http://linux.about.com/od/commands/fl/The-Bash-bc-Calculator.htm

The Bash bc Calculator

Interactive Math Utility with Arbitrary Precision

The program bc is a simple yet powerful interactive calculator.

All you need to do is type "bc" in terminal (command line), hit return, and start typing mathematical expressions:

     bc

After displaying a message about the software, the program is ready receive your input. If you type

     2 + 2

and hit return, to program will display the result:

     4

You can use variables as follows:

     a = 5

which creates a variable "a" and assigns the value 5 to it. (Remember to hit return after each line.)

Now if enter "a":

     a

the program will respond with the value of the variable "a":

     5

Now, if assign "7" to the variable "b":

     b = 7

You can compute the sum of the "a" and "b" using:

     a + b

yielding:

     12

One of the distinguishing features of the bc is the ability to define precision to any level. This is done by specifying the number of decimals that are computed for any number.

By default the number of decimals used is 0, and it can be changed using the "scale" variable. Using the default value of 0, computing the quotient of "a" and "b":

     a / b

will be "0", since no decimals will be shown. If you set the value of "scale" to "2":

     scale = 2

The quotient "a / b" will be shown as:

     .71

If you set it to 50, this quotient will be shown as:

     .71428571428571428571428571428571428571428571428571

You can also define new functions in bc.

 

See also: