# Bc (programming language)

The Basic Calculator (short bc ) is a dedicated computing language, which is similar to the syntax of C. The out alternate feature of bc is the ability to calculate with floating point numbers in almost any great accuracy; the limit is depending on the version at least several thousand places, but mostly at several millions to billions. bc does not use the co-processor or other hardware floating point unit of a computer, but works internally with integers; the Gleitkommafähigkeit is produced purely by software. Only in this way can the language achieve higher accuracy than is provided in the floating-point hardware. However, bc is thus inherently much slower than a language that performs floating-point calculations directly in hardware.

Bc is commonly used by a command line under a Unix derivative, or by other programs to perform complex calculations. The original program is POSIX bc; which GNU has derived its own version and capability, which is more commonly used today. Both versions can be used as a mathematical scripting language or as an interactive shell.

## POSIX bc

The standardized language POSIX bc is based on DC and thus makes it possible to combine the capacities of the DC language with a simple input syntax. In other words, similar to bc a dc front-end with additional features, including variables, arrays, some arithmetic functions ( the only integrated is sqrt (), square root, the other accessed from the standard library ) and loop constructs ( if (condition ) ... while (condition) ... and for ( init, condition, inc) ), which are often similar to C.

Functions are created with define; with return can be defined within this a return value.

## GNU bc

GNU bc is a fork of POSIX bc and includes many enhancements. It builds no longer on dc on, but instead is written in C. Nevertheless, it is backward compatible to POSIX bc, ie, all POSIX bc programs run on GNU bc, but not necessarily vice versa.

Among other things, the names of variables, arrays, and functions can now be longer than one character, and the if condition was added in GNU bc is an optional else clause. Moreover, a read ( ) statement allows the reading of numbers from standard input, which interactive user input in a program are possible.

In addition to the standard output method GNU bc has a p- function (print). Apart from the standard C comments ( / ** / ), which is also possible in POSIX bc, there is still GNU # character to initiate single-line comments.

By default, the Basic Calculator only basic functionality, such as the exponential function, the trigonometric functions and the natural logarithm. It further functions themselves can, however, be defined.

### Example

The following example defines a procedure which recursively the Faculty of x! the number x is calculated.

Define fact ( x ) { if ( x <1) return 1 return ( x * fact ( x -1)) } Entering

Fact ( 10) is thus obtained 10! = 3,628,800th