BC(1) | User Commands | BC(1) |

/usr/bin/bc[-c] [-l] [file]...

/usr/xpg6/bin/bc[-c] [-l] [file]...

*L*

Means a letter **a**−**z**,

*E*

Means an expression: a (mathematical or logical) value,
an operand that takes a value, or a combination of operands and operators that
evaluates to a value,

*S*

Means a statement.

Simple variables:

Array elements:

The words

**sqrt ( ***E*** )**

Square root

**length ( ***E*** )**

Number of significant decimal digits.

**scale ( ***E*** )**

Number of digits right of decimal point.

*L ***( ***E* , ... , *E*** )**

(**%** is remainder; **^** is power)

**++ −− **

(prefix and postfix; apply to names)

**== <= >= != < >**

**= =+ =− =* =/ =% =^**

null statement

.string

sine

**c(***x***)**

cosine

**e(***x***)**

exponential

**l(***x***)**

log

**a(***x***)**

arctangent

**j(***n***,***x)*

Bessel function

All function arguments are passed by value.

The value of a statement that is an expression is printed unless
the main operator is an assignment. Either semicolons or new-lines may
separate statements. Assignment to **scale** influences the number of
digits to be retained on arithmetic operations in the manner of **dc**.
Assignments to **ibase** or **obase** set the input and output number
radix respectively.

The same letter may be used as an array, a function, and a simple
variable simultaneously. All variables are global to the program.
**auto** variables are stacked during function calls. When using arrays
as function arguments or defining them as automatic variables, empty square
brackets must follow the array name.

**-c**

Compiles only. The output is **dc** commands that are
sent to the standard output.

Defines the math functions and initializes **scale**
to **20**, instead of the default zero.

Defines the math functions and initializes **scale**
to **20**, instead of the default zero. All math results have the scale of
**20**.

*file*

A pathname of a text file containing **bc** program
statements. After all cases of *file* have been read, **bc** reads the
standard input.

In the shell, the following assigns an approximation of the first
ten digits of **n** to the variable *x*:

x=$(printf "%s\n" 'scale = 10; 104348/33215' | bc)

**Example 2 **Defining a computing function

Defines a function to compute an approximate value of the exponential function:

scale = 20define e(x){auto a, b, c, i, sa = 1b = 1s = 1for(i=1; 1==1; i++){a = a*xb = b*ic = a/bif(c == 0) return(s)s = s+c}}

**Example 3 **Printing the approximate values of the
function

Prints approximate values of the exponential function of the first ten integers:

for(i=1; i<=10; i++) e(i)

or

for (i = 1; i <= 10; ++i) { e(i) }

**0**

All input files were processed successfully.

**unspecified**

An error occurred.

mathematical library

**/usr/include/limits.h**

to define BC_ parameters

ATTRIBUTE TYPE | ATTRIBUTE VALUE |

Interface Stability | Standard |

The **for** statement must have all three expressions
(*E*'s).

August 29, 2003 |